feat: how to play dialog is timed and manually dismissible (#251)

* chore: autoclose how to play dialog after 3 seconds

* test: added test for barrier dismiss on tap
pull/242/head
jonathandaniels-vgv 3 years ago committed by GitHub
parent e00fed5c1c
commit b5ced0113f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,7 @@
// ignore_for_file: public_member_api_docs
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/l10n/l10n.dart';
@ -46,19 +48,34 @@ class CharacterSelectionView extends StatelessWidget {
const SizedBox(height: 20),
TextButton(
onPressed: () {
Navigator.of(context).pop();
late Timer timer;
// TODO(arturplaczek): remove after merge StarBlocListener
final height = MediaQuery.of(context).size.height * 0.5;
Navigator.of(context).pop();
showDialog<void>(
context: context,
builder: (_) => Center(
builder: (context) {
timer = Timer(
const Duration(seconds: 3),
() {
Navigator.of(context).pop();
},
);
return Center(
child: SizedBox(
height: height,
width: height * 1.4,
child: const HowToPlayDialog(),
),
),
);
},
).then(
(_) {
if (timer.isActive) {
timer.cancel();
}
},
);
},
child: Text(l10n.start),

@ -1,5 +1,7 @@
// ignore_for_file: prefer_const_constructors
import 'dart:async';
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@ -84,7 +86,9 @@ void main() {
.called(1);
});
testWidgets('displays how to play dialog when start is tapped',
group('HowToPlayDialog', () {
testWidgets(
'is displayed for 3 seconds when start is tapped',
(tester) async {
await tester.pumpApp(
CharacterSelectionView(),
@ -93,8 +97,43 @@ void main() {
await tester.ensureVisible(find.byType(TextButton));
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
expect(find.byType(HowToPlayDialog), findsOneWidget);
await tester.pump(Duration(seconds: 3));
await tester.pumpAndSettle();
expect(find.byType(HowToPlayDialog), findsNothing);
},
);
testWidgets(
'can be dismissed manually before 3 seconds have passed',
(tester) async {
await tester.pumpApp(
Scaffold(
body: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
Navigator.of(context)
.push<void>(CharacterSelectionDialog.route());
},
child: Text('Tap me'),
);
},
),
),
characterThemeCubit: characterThemeCubit,
);
await tester.tap(find.text('Tap me'));
await tester.pumpAndSettle();
await tester.ensureVisible(find.byType(TextButton));
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
expect(find.byType(HowToPlayDialog), findsOneWidget);
await tester.tapAt(Offset(1, 1));
await tester.pumpAndSettle();
expect(find.byType(HowToPlayDialog), findsNothing);
},
);
});
});

Loading…
Cancel
Save