chore: update dialogs

pull/247/head
arturplaczek 3 years ago
parent c28c582424
commit 69b66e51d3

@ -3,10 +3,8 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/gen/gen.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball_audio/pinball_audio.dart';
import 'package:pinball_ui/pinball_ui.dart';
import 'package:platform_helper/platform_helper.dart';
@ -51,24 +49,16 @@ extension on Control {
}
}
Future<void> showHowToPlayDialog(BuildContext context) {
final audio = context.read<PinballAudio>();
return showDialog<void>(
context: context,
builder: (_) => HowToPlayDialog(),
).then((_) {
audio.ioPinballVoiceOver();
});
}
class HowToPlayDialog extends StatefulWidget {
HowToPlayDialog({
Key? key,
required this.onDismissCallback,
@visibleForTesting PlatformHelper? platformHelper,
}) : platformHelper = platformHelper ?? PlatformHelper(),
super(key: key);
final PlatformHelper platformHelper;
final VoidCallback onDismissCallback;
@override
State<HowToPlayDialog> createState() => _HowToPlayDialogState();
@ -82,6 +72,7 @@ class _HowToPlayDialogState extends State<HowToPlayDialog> {
closeTimer = Timer(const Duration(seconds: 3), () {
if (mounted) {
Navigator.of(context).pop();
widget.onDismissCallback.call();
}
});
}
@ -96,10 +87,17 @@ class _HowToPlayDialogState extends State<HowToPlayDialog> {
Widget build(BuildContext context) {
final isMobile = widget.platformHelper.isMobile;
final l10n = context.l10n;
return PinballDialog(
return WillPopScope(
onWillPop: () {
widget.onDismissCallback.call();
return Future.value(true);
},
child: PinballDialog(
title: l10n.howToPlay,
subtitle: l10n.tipsForFlips,
child: isMobile ? const _MobileBody() : const _DesktopBody(),
),
);
}
}

@ -1,20 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/how_to_play/how_to_play.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/select_character/select_character.dart';
import 'package:pinball/start_game/start_game.dart';
import 'package:pinball_theme/pinball_theme.dart';
import 'package:pinball_ui/pinball_ui.dart';
/// Inflates [CharacterSelectionDialog] using [showDialog].
Future<void> showCharacterSelectionDialog(BuildContext context) {
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (_) => const CharacterSelectionDialog(),
);
}
/// {@template character_selection_dialog}
/// Dialog used to select the playing character of the game.
/// {@endtemplate character_selection_dialog}
@ -59,7 +50,7 @@ class _SelectCharacterButton extends StatelessWidget {
return PinballButton(
onTap: () async {
Navigator.of(context).pop();
await showHowToPlayDialog(context);
context.read<StartGameBloc>().add(const CharacterSelected());
},
text: l10n.select,
);

@ -25,7 +25,11 @@ void main() {
testWidgets(
'can be instantiated without passing in a platform helper',
(tester) async {
await tester.pumpApp(HowToPlayDialog());
await tester.pumpApp(
HowToPlayDialog(
onDismissCallback: () {},
),
);
expect(find.byType(HowToPlayDialog), findsOneWidget);
},
);
@ -35,6 +39,7 @@ void main() {
await tester.pumpApp(
HowToPlayDialog(
platformHelper: platformHelper,
onDismissCallback: () {},
),
);
expect(find.text(l10n.howToPlay), findsOneWidget);
@ -49,6 +54,7 @@ void main() {
await tester.pumpApp(
HowToPlayDialog(
platformHelper: platformHelper,
onDismissCallback: () {},
),
);
expect(find.text(l10n.howToPlay), findsOneWidget);
@ -62,7 +68,12 @@ void main() {
Builder(
builder: (context) {
return TextButton(
onPressed: () => showHowToPlayDialog(context),
onPressed: () => showDialog<void>(
context: context,
builder: (_) => HowToPlayDialog(
onDismissCallback: () {},
),
),
child: const Text('test'),
);
},
@ -82,7 +93,12 @@ void main() {
Builder(
builder: (context) {
return TextButton(
onPressed: () => showHowToPlayDialog(context),
onPressed: () => showDialog<void>(
context: context,
builder: (_) => HowToPlayDialog(
onDismissCallback: () {},
),
),
child: const Text('test'),
);
},
@ -96,30 +112,5 @@ void main() {
await tester.pumpAndSettle();
expect(find.byType(HowToPlayDialog), findsNothing);
});
testWidgets(
'plays the I/O Pinball voice over audio on dismiss',
(tester) async {
final audio = _MockPinballAudio();
await tester.pumpApp(
Builder(
builder: (context) {
return TextButton(
onPressed: () => showHowToPlayDialog(context),
child: const Text('test'),
);
},
),
pinballAudio: audio,
);
expect(find.byType(HowToPlayDialog), findsNothing);
await tester.tap(find.text('test'));
await tester.pumpAndSettle();
await tester.tapAt(Offset.zero);
await tester.pumpAndSettle();
verify(audio.ioPinballVoiceOver).called(1);
},
);
});
}

@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pinball/how_to_play/how_to_play.dart';
import 'package:pinball/select_character/select_character.dart';
import 'package:pinball/start_game/start_game.dart';
import 'package:pinball_theme/pinball_theme.dart';
import 'package:pinball_ui/pinball_ui.dart';
@ -11,14 +12,19 @@ import '../../helpers/helpers.dart';
class _MockCharacterThemeCubit extends Mock implements CharacterThemeCubit {}
class _MockStartGameBloc extends Mock implements StartGameBloc {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late CharacterThemeCubit characterThemeCubit;
late StartGameBloc startGameBloc;
setUp(() async {
await mockFlameImages();
characterThemeCubit = _MockCharacterThemeCubit();
startGameBloc = _MockStartGameBloc();
whenListen(
characterThemeCubit,
const Stream<CharacterThemeState>.empty(),
@ -29,25 +35,6 @@ void main() {
});
group('CharacterSelectionDialog', () {
group('showCharacterSelectionDialog', () {
testWidgets('inflates the dialog', (tester) async {
await tester.pumpApp(
Builder(
builder: (context) {
return TextButton(
onPressed: () => showCharacterSelectionDialog(context),
child: const Text('test'),
);
},
),
characterThemeCubit: characterThemeCubit,
);
await tester.tap(find.text('test'));
await tester.pump();
expect(find.byType(CharacterSelectionDialog), findsOneWidget);
});
});
testWidgets('selecting a new character calls characterSelected on cubit',
(tester) async {
await tester.pumpApp(
@ -67,6 +54,7 @@ void main() {
await tester.pumpApp(
const CharacterSelectionDialog(),
characterThemeCubit: characterThemeCubit,
startGameBloc: startGameBloc,
);
await tester.tap(find.byType(PinballButton));
await tester.pumpAndSettle();

Loading…
Cancel
Save