chore: autoclose how to play dialog after 3 seconds

pull/251/head
Jonathan Daniels 3 years ago
parent aa551f9e70
commit 6da959241a

@ -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';
@ -47,10 +49,20 @@ class CharacterSelectionView extends StatelessWidget {
TextButton(
onPressed: () {
Navigator.of(context).pop();
late Timer timer;
showDialog<void>(
context: context,
builder: (_) => const HowToPlayDialog(),
);
builder: (context) {
timer = Timer(const Duration(seconds: 3), () {
Navigator.of(context).pop();
});
return 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,8 @@ void main() {
.called(1);
});
testWidgets('displays how to play dialog when start is tapped',
testWidgets(
'displays how to play dialog for 3 seconds when start is tapped',
(tester) async {
await tester.pumpApp(
CharacterSelectionView(),
@ -93,9 +96,12 @@ 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('CharacterImageButton renders correctly', (tester) async {

Loading…
Cancel
Save