fix: apply code review

pull/191/head
arturplaczek 3 years ago
parent d01f46a63f
commit 77c4403cbd

@ -9,9 +9,10 @@ import 'package:pinball/gen/assets.gen.dart';
class BonusAnimation extends StatelessWidget { class BonusAnimation extends StatelessWidget {
const BonusAnimation._( const BonusAnimation._(
this.imagePath, { this.imagePath, {
this.onCompleted, VoidCallback? onCompleted,
Key? key, Key? key,
}) : super(key: key); }) : _onCompleted = onCompleted,
super(key: key);
BonusAnimation.dashNest({ BonusAnimation.dashNest({
Key? key, Key? key,
@ -42,7 +43,7 @@ class BonusAnimation extends StatelessWidget {
final String imagePath; final String imagePath;
final VoidCallback? onCompleted; final VoidCallback? _onCompleted;
static Future<void> loadAssets() { static Future<void> loadAssets() {
Flame.images.prefix = ''; Flame.images.prefix = '';
@ -50,7 +51,7 @@ class BonusAnimation extends StatelessWidget {
Assets.images.bonusAnimation.dashNest.keyName, Assets.images.bonusAnimation.dashNest.keyName,
Assets.images.bonusAnimation.sparkyTurboCharge.keyName, Assets.images.bonusAnimation.sparkyTurboCharge.keyName,
Assets.images.bonusAnimation.dino.keyName, Assets.images.bonusAnimation.dino.keyName,
// TODO: add google word animation asset here // TODO(arturplaczek): add google word animation asset here
]); ]);
} }
@ -71,7 +72,7 @@ class BonusAnimation extends StatelessWidget {
Future<void>.delayed( Future<void>.delayed(
Duration(seconds: animation.totalDuration().ceil()), Duration(seconds: animation.totalDuration().ceil()),
() { () {
onCompleted?.call(); _onCompleted?.call();
}, },
); );

@ -9,6 +9,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/view/widgets/bonus_animation.dart'; import 'package:pinball/game/view/widgets/bonus_animation.dart';
import '../../../helpers/helpers.dart';
class MockImages extends Mock implements Images {} class MockImages extends Mock implements Images {}
class MockImage extends Mock implements ui.Image {} class MockImage extends Mock implements ui.Image {}
@ -20,10 +22,9 @@ void main() {
await BonusAnimation.loadAssets(); await BonusAnimation.loadAssets();
}); });
group('loads correctly SpriteAnimationWidget for', () { group('loads SpriteAnimationWidget correctly for', () {
testWidgets('dashNest', (tester) async { testWidgets('dashNest', (tester) async {
await tester.runAsync(() async { await tester.pumpApp(
await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
body: BonusAnimation.dashNest(), body: BonusAnimation.dashNest(),
@ -34,11 +35,9 @@ void main() {
expect(find.byType(SpriteAnimationWidget), findsOneWidget); expect(find.byType(SpriteAnimationWidget), findsOneWidget);
}); });
});
testWidgets('dino', (tester) async { testWidgets('dino', (tester) async {
await tester.runAsync(() async { await tester.pumpApp(
await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
body: BonusAnimation.dino(), body: BonusAnimation.dino(),
@ -49,11 +48,9 @@ void main() {
expect(find.byType(SpriteAnimationWidget), findsOneWidget); expect(find.byType(SpriteAnimationWidget), findsOneWidget);
}); });
});
testWidgets('sparkyTurboCharge', (tester) async { testWidgets('sparkyTurboCharge', (tester) async {
await tester.runAsync(() async { await tester.pumpApp(
await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
body: BonusAnimation.sparkyTurboCharge(), body: BonusAnimation.sparkyTurboCharge(),
@ -65,11 +62,10 @@ void main() {
expect(find.byType(SpriteAnimationWidget), findsOneWidget); expect(find.byType(SpriteAnimationWidget), findsOneWidget);
}); });
}); });
});
// TODO(arturplaczek): refactor this test when there is // TODO(arturplaczek): refactor this test when there is a new version of the
// a new version of the flame with // flame with an onComplete callback in SpriteAnimationWidget
// an onComplete callback in SpriteAnimationWidget // https://github.com/flame-engine/flame/issues/1543
testWidgets('called onCompleted callback at the end of animation ', testWidgets('called onCompleted callback at the end of animation ',
(tester) async { (tester) async {
final completer = Completer<void>(); final completer = Completer<void>();
@ -95,70 +91,3 @@ void main() {
}); });
}); });
} }
const transparentImage = <int>[
0x89,
0x50,
0x4E,
0x47,
0x0D,
0x0A,
0x1A,
0x0A,
0x00,
0x00,
0x00,
0x0D,
0x49,
0x48,
0x44,
0x52,
0x00,
0x00,
0x00,
0x01,
0x00,
0x00,
0x00,
0x01,
0x08,
0x06,
0x00,
0x00,
0x00,
0x1F,
0x15,
0xC4,
0x89,
0x00,
0x00,
0x00,
0x0A,
0x49,
0x44,
0x41,
0x54,
0x78,
0x9C,
0x63,
0x00,
0x01,
0x00,
0x00,
0x05,
0x00,
0x01,
0x0D,
0x0A,
0x2D,
0xB4,
0x00,
0x00,
0x00,
0x00,
0x49,
0x45,
0x4E,
0x44,
0xAE,
];

Loading…
Cancel
Save