feat(flutter): 重做品牌开屏动画
This commit is contained in:
1 parent
499e42b511
commit
15570f117a
2 files changed
+243
-56
No files matched your search
@@ -3,6 +3,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/home_feed.dart';
|
||||
@@ -10,38 +11,66 @@ import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
|
||||
import 'package:fruitshorts/core/data/services/catalog_controller.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/home/home_view.dart';
|
||||
import 'package:fruitshorts/pages/splash/splash_page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'should_keep_splash_with_loading_until_home_feed_settles',
|
||||
(tester) async {
|
||||
final repository = _PendingCatalog();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: ChangeNotifierProvider(
|
||||
create: (_) => CatalogController(repository)..load(),
|
||||
child: const HomePage(),
|
||||
),
|
||||
testWidgets('should_keep_splash_with_loading_until_home_feed_settles', (
|
||||
tester,
|
||||
) async {
|
||||
final repository = _PendingCatalog();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: ChangeNotifierProvider(
|
||||
create: (_) => CatalogController(repository)..load(),
|
||||
child: const HomePage(),
|
||||
),
|
||||
);
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byKey(const Key('splash-screen')), findsOneWidget);
|
||||
expect(find.byKey(const Key('splash-loading')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-empty')), findsNothing);
|
||||
final clip = tester.widget<ClipRRect>(find.byType(ClipRRect));
|
||||
expect(clip.borderRadius, BorderRadius.circular(18));
|
||||
expect(find.byKey(const Key('splash-screen')), findsOneWidget);
|
||||
expect(find.byKey(const Key('splash-loading')), findsOneWidget);
|
||||
expect(find.byKey(const Key('home-empty')), findsNothing);
|
||||
final clip = tester.widget<ClipRRect>(find.byType(ClipRRect));
|
||||
expect(clip.borderRadius, BorderRadius.circular(24));
|
||||
|
||||
repository.pending.complete(const HomeFeed());
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
repository.pending.complete(const HomeFeed());
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byKey(const Key('splash-screen')), findsNothing);
|
||||
expect(find.byKey(const Key('home-empty')), findsOneWidget);
|
||||
},
|
||||
);
|
||||
expect(find.byKey(const Key('splash-screen')), findsNothing);
|
||||
expect(find.byKey(const Key('home-empty')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_animate_brand_copy_and_loading_to_full_opacity', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: SplashPage()));
|
||||
|
||||
expect(find.byKey(const Key('splash-screen')), findsOneWidget);
|
||||
expect(find.byKey(const Key('splash-brand')), findsOneWidget);
|
||||
expect(find.byKey(const Key('splash-tagline')), findsOneWidget);
|
||||
expect(find.byKey(const Key('splash-loading')), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<ColoredBox>(find.byKey(const Key('splash-screen'))).color,
|
||||
const Color(0xFF100C0A),
|
||||
);
|
||||
final overlay = tester.widget<AnnotatedRegion<SystemUiOverlayStyle>>(
|
||||
find.byType(AnnotatedRegion<SystemUiOverlayStyle>).first,
|
||||
);
|
||||
expect(overlay.value.statusBarIconBrightness, Brightness.light);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 1200));
|
||||
|
||||
double opacity(String key) =>
|
||||
tester.widget<FadeTransition>(find.byKey(Key(key))).opacity.value;
|
||||
expect(opacity('splash-logo-fade'), 1);
|
||||
expect(opacity('splash-brand-fade'), 1);
|
||||
expect(opacity('splash-tagline-fade'), 1);
|
||||
expect(opacity('splash-loading-fade'), 1);
|
||||
});
|
||||
}
|
||||
|
||||
class _PendingCatalog implements CatalogRepository {
|
||||
|
||||
Reference in new issue
Block a user