refactor: provide GameBloc in App (#370)

pull/374/head
Felix Angelov 3 years ago committed by GitHub
parent d2372b539f
commit 2c0f8b045c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,6 +39,7 @@ class App extends StatelessWidget {
providers: [ providers: [
BlocProvider(create: (_) => CharacterThemeCubit()), BlocProvider(create: (_) => CharacterThemeCubit()),
BlocProvider(create: (_) => StartGameBloc()), BlocProvider(create: (_) => StartGameBloc()),
BlocProvider(create: (_) => GameBloc()),
], ],
child: MaterialApp( child: MaterialApp(
title: 'I/O Pinball', title: 'I/O Pinball',

@ -23,15 +23,9 @@ class PinballGamePage extends StatelessWidget {
final bool isDebugMode; final bool isDebugMode;
static Route route({ static Route route({bool isDebugMode = kDebugMode}) {
bool isDebugMode = kDebugMode,
}) {
return MaterialPageRoute<void>( return MaterialPageRoute<void>(
builder: (context) { builder: (_) => PinballGamePage(isDebugMode: isDebugMode),
return PinballGamePage(
isDebugMode: isDebugMode,
);
},
); );
} }
@ -41,11 +35,6 @@ class PinballGamePage extends StatelessWidget {
context.read<CharacterThemeCubit>().state.characterTheme; context.read<CharacterThemeCubit>().state.characterTheme;
final player = context.read<PinballPlayer>(); final player = context.read<PinballPlayer>();
final leaderboardRepository = context.read<LeaderboardRepository>(); final leaderboardRepository = context.read<LeaderboardRepository>();
return BlocProvider(
create: (_) => GameBloc(),
child: Builder(
builder: (context) {
final gameBloc = context.read<GameBloc>(); final gameBloc = context.read<GameBloc>();
final game = isDebugMode final game = isDebugMode
? DebugPinballGame( ? DebugPinballGame(
@ -74,9 +63,6 @@ class PinballGamePage extends StatelessWidget {
create: (_) => AssetsManagerCubit(loadables)..load(), create: (_) => AssetsManagerCubit(loadables)..load(),
child: PinballGameView(game: game), child: PinballGameView(game: game),
); );
},
),
);
} }
} }

@ -84,6 +84,7 @@ void main() {
await tester.pumpApp( await tester.pumpApp(
PinballGamePage(), PinballGamePage(),
characterThemeCubit: characterThemeCubit, characterThemeCubit: characterThemeCubit,
gameBloc: gameBloc,
); );
expect(find.byType(PinballGameView), findsOneWidget); expect(find.byType(PinballGameView), findsOneWidget);
@ -172,6 +173,7 @@ void main() {
), ),
), ),
characterThemeCubit: characterThemeCubit, characterThemeCubit: characterThemeCubit,
gameBloc: gameBloc,
); );
await tester.tap(find.text('Tap me')); await tester.tap(find.text('Tap me'));

Loading…
Cancel
Save