chore: moved timer logic to how to play dialog

pull/242/head
Jonathan Daniels 3 years ago
parent cfd7be0974
commit 9e5d6dccb8

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

@ -1,5 +1,7 @@
// ignore_for_file: public_member_api_docs // ignore_for_file: public_member_api_docs
import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball/gen/gen.dart'; import 'package:pinball/gen/gen.dart';
@ -49,9 +51,31 @@ extension on Control {
} }
} }
class HowToPlayDialog extends StatelessWidget { class HowToPlayDialog extends StatefulWidget {
const HowToPlayDialog({Key? key}) : super(key: key); const HowToPlayDialog({Key? key}) : super(key: key);
@override
State<HowToPlayDialog> createState() => _HowToPlayDialogState();
}
class _HowToPlayDialogState extends State<HowToPlayDialog> {
late Timer closeTimer;
@override
void initState() {
super.initState();
closeTimer = Timer(const Duration(seconds: 3), () {
if (mounted) {
Navigator.of(context).maybePop();
}
});
}
@override
void dispose() {
closeTimer.cancel();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isMobile = defaultTargetPlatform == TargetPlatform.iOS || final isMobile = defaultTargetPlatform == TargetPlatform.iOS ||

@ -91,9 +91,23 @@ void main() {
'is displayed for 3 seconds when start is tapped', 'is displayed for 3 seconds when start is tapped',
(tester) async { (tester) async {
await tester.pumpApp( await tester.pumpApp(
CharacterSelectionView(), Scaffold(
body: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
Navigator.of(context)
.push<void>(CharacterSelectionDialog.route());
},
child: Text('Tap me'),
);
},
),
),
characterThemeCubit: characterThemeCubit, characterThemeCubit: characterThemeCubit,
); );
await tester.tap(find.text('Tap me'));
await tester.pumpAndSettle();
await tester.ensureVisible(find.byType(TextButton)); await tester.ensureVisible(find.byType(TextButton));
await tester.tap(find.byType(TextButton)); await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle(); await tester.pumpAndSettle();

Loading…
Cancel
Save