fix: apply code review

pull/195/head
arturplaczek 3 years ago
parent 88c8b45d81
commit 6a9c8a5557

@ -37,20 +37,14 @@ class App extends StatelessWidget {
], ],
child: BlocProvider( child: BlocProvider(
create: (context) => ThemeCubit(), create: (context) => ThemeCubit(),
child: MaterialApp( child: const MaterialApp(
title: 'I/O Pinball', title: 'I/O Pinball',
theme: ThemeData( localizationsDelegates: [
appBarTheme: const AppBarTheme(color: Color(0xFF13B9FF)),
colorScheme: ColorScheme.fromSwatch(
accentColor: const Color(0xFF13B9FF),
),
),
localizationsDelegates: const [
AppLocalizations.delegate, AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate, GlobalMaterialLocalizations.delegate,
], ],
supportedLocales: AppLocalizations.supportedLocales, supportedLocales: AppLocalizations.supportedLocales,
home: const PinballGamePage(), home: PinballGamePage(),
), ),
), ),
); );

@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart'; import 'package:pinball/game/game.dart';
import 'package:pinball/start_game/bloc/start_game_bloc.dart'; import 'package:pinball/start_game/start_game.dart';
import 'package:pinball/theme/theme.dart'; import 'package:pinball/theme/theme.dart';
import 'package:pinball_audio/pinball_audio.dart'; import 'package:pinball_audio/pinball_audio.dart';
@ -76,17 +76,16 @@ class PinballGameView extends StatelessWidget {
return Scaffold( return Scaffold(
backgroundColor: Colors.blue, backgroundColor: Colors.blue,
body: isLoading body: isLoading
? const PinballGameLoadedView() ? const _PinballGameLoadingView()
: PinballGameBody( : PinballGameLoadedView(
game: game, game: game,
), ),
); );
} }
} }
@visibleForTesting class _PinballGameLoadingView extends StatelessWidget {
class PinballGameLoadedView extends StatelessWidget { const _PinballGameLoadingView({Key? key}) : super(key: key);
const PinballGameLoadedView({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -107,8 +106,8 @@ class PinballGameLoadedView extends StatelessWidget {
} }
@visibleForTesting @visibleForTesting
class PinballGameBody extends StatelessWidget { class PinballGameLoadedView extends StatelessWidget {
const PinballGameBody({ const PinballGameLoadedView({
Key? key, Key? key,
required this.game, required this.game,
}) : super(key: key); }) : super(key: key);

@ -34,7 +34,7 @@ class PlayButtonOverlay extends StatelessWidget {
child: SizedBox( child: SizedBox(
height: height, height: height,
width: width, width: width,
child: const CharacterSelectionPage(), child: const CharacterSelectionDialog(),
), ),
); );
}, },

@ -69,7 +69,7 @@ class LeaderboardView extends StatelessWidget {
const SizedBox(height: 20), const SizedBox(height: 20),
TextButton( TextButton(
onPressed: () => Navigator.of(context).push<void>( onPressed: () => Navigator.of(context).push<void>(
CharacterSelectionPage.route(), CharacterSelectionDialog.route(),
), ),
child: Text(l10n.retry), child: Text(l10n.retry),
), ),

@ -7,12 +7,12 @@ import 'package:pinball/start_game/start_game.dart';
import 'package:pinball/theme/theme.dart'; import 'package:pinball/theme/theme.dart';
import 'package:pinball_theme/pinball_theme.dart'; import 'package:pinball_theme/pinball_theme.dart';
class CharacterSelectionPage extends StatelessWidget { class CharacterSelectionDialog extends StatelessWidget {
const CharacterSelectionPage({Key? key}) : super(key: key); const CharacterSelectionDialog({Key? key}) : super(key: key);
static Route route() { static Route route() {
return MaterialPageRoute<void>( return MaterialPageRoute<void>(
builder: (_) => const CharacterSelectionPage(), builder: (_) => const CharacterSelectionDialog(),
); );
} }

@ -72,22 +72,37 @@ void main() {
), ),
findsOneWidget, findsOneWidget,
); );
},
);
final loadedAssetsState = AssetsManagerState( testWidgets(
loadables: [Future<void>.value()], 'renders PinballGameLoadedView after resources have been loaded',
loaded: [Future<void>.value()], (tester) async {
); final assetsManagerCubit = MockAssetsManagerCubit();
whenListen(
assetsManagerCubit, final loadedAssetsState = AssetsManagerState(
Stream.value(loadedAssetsState), loadables: [Future<void>.value()],
initialState: loadedAssetsState, loaded: [Future<void>.value()],
); );
whenListen(
assetsManagerCubit,
Stream.value(loadedAssetsState),
initialState: loadedAssetsState,
);
await tester.pumpApp(
PinballGameView(
game: game,
),
assetsManagerCubit: assetsManagerCubit,
themeCubit: themeCubit,
gameBloc: gameBloc,
);
await tester.pump(); await tester.pump();
expect(find.byType(PinballGameBody), findsOneWidget); expect(find.byType(PinballGameLoadedView), findsOneWidget);
}, });
);
group('route', () { group('route', () {
Future<void> pumpRoute({ Future<void> pumpRoute({

@ -33,14 +33,14 @@ void main() {
verify(gameFlowController.start).called(1); verify(gameFlowController.start).called(1);
}); });
testWidgets('is showing CharacterSelectionPage dialog when taped', testWidgets('is showing CharacterSelectionPage dialog when tapped',
(tester) async { (tester) async {
await tester.pumpApp(PlayButtonOverlay(game: game)); await tester.pumpApp(PlayButtonOverlay(game: game));
await tester.tap(find.text('Play')); await tester.tap(find.text('Play'));
await tester.pump(); await tester.pump();
expect(find.byType(CharacterSelectionPage), findsOneWidget); expect(find.byType(CharacterSelectionDialog), findsOneWidget);
}); });
}); });
} }

@ -25,7 +25,7 @@ void main() {
group('CharacterSelectionPage', () { group('CharacterSelectionPage', () {
testWidgets('renders CharacterSelectionView', (tester) async { testWidgets('renders CharacterSelectionView', (tester) async {
await tester.pumpApp( await tester.pumpApp(
CharacterSelectionPage(), CharacterSelectionDialog(),
themeCubit: themeCubit, themeCubit: themeCubit,
); );
expect(find.byType(CharacterSelectionView), findsOneWidget); expect(find.byType(CharacterSelectionView), findsOneWidget);
@ -39,7 +39,7 @@ void main() {
return ElevatedButton( return ElevatedButton(
onPressed: () { onPressed: () {
Navigator.of(context) Navigator.of(context)
.push<void>(CharacterSelectionPage.route()); .push<void>(CharacterSelectionDialog.route());
}, },
child: Text('Tap me'), child: Text('Tap me'),
); );
@ -52,7 +52,7 @@ void main() {
await tester.tap(find.text('Tap me')); await tester.tap(find.text('Tap me'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byType(CharacterSelectionPage), findsOneWidget); expect(find.byType(CharacterSelectionDialog), findsOneWidget);
}); });
}); });

Loading…
Cancel
Save