From 4279e7961c0ef219c454c08a8e1ac75d81fb9df6 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Fri, 3 Mar 2023 18:26:44 +0100 Subject: [PATCH] Add Timer to Popup --- lib/providers/timer_provider.dart | 4 +++ lib/widgets/popup_for_task_done.dart | 41 ++++++++++++++++++++++++++++ lib/widgets/view_form_page.dart | 13 ++------- 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 lib/widgets/popup_for_task_done.dart diff --git a/lib/providers/timer_provider.dart b/lib/providers/timer_provider.dart index 54a2679..f5a75c1 100644 --- a/lib/providers/timer_provider.dart +++ b/lib/providers/timer_provider.dart @@ -8,6 +8,7 @@ class TimerProvider extends ChangeNotifier { int get elapsedSeconds => _timer != null ? _timer!.tick : 0; void startTimer(Duration duration) { + print('started'); started = true; _timer = Timer.periodic(const Duration(seconds: 1), ((timer) { if (timer.tick >= duration.inSeconds) { @@ -26,7 +27,10 @@ class TimerProvider extends ChangeNotifier { @override void dispose() { + print('disposed'); + started = false; _timer?.cancel(); + _timer = null; super.dispose(); } } diff --git a/lib/widgets/popup_for_task_done.dart b/lib/widgets/popup_for_task_done.dart new file mode 100644 index 0000000..fe63907 --- /dev/null +++ b/lib/widgets/popup_for_task_done.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/timer_provider.dart'; +import 'package:smoke_cess_app/widgets/timer_widget.dart'; +import '../services/date_service.dart'; +import '../services/pages_service.dart'; + +void showTaskDonePopup(BuildContext context, Pages page) async { + Duration duration = await getTimeTill(page); + await showDialog( + context: context, + builder: (BuildContext context) { + return ChangeNotifierProvider( + create: (context) => TimerProvider(), + child: TaskDonePopup( + duration: duration, + ), + ); + }, + ); +} + +class TaskDonePopup extends StatelessWidget { + final Duration duration; + const TaskDonePopup({super.key, required this.duration}); + + @override + Widget build(BuildContext context) { + TimerProvider timerProvider = context.read(); + timerProvider.startTimer(duration); + return AlertDialog( + title: const Text('Schon gemacht'), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('Nächstes mal wieder:'), + TimerWidget(duration: duration) + ])); + } +} diff --git a/lib/widgets/view_form_page.dart b/lib/widgets/view_form_page.dart index aa52fd1..57b9271 100644 --- a/lib/widgets/view_form_page.dart +++ b/lib/widgets/view_form_page.dart @@ -1,10 +1,10 @@ -import 'package:awesome_dialog/awesome_dialog.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/services/pages_service.dart'; import '../providers/input_provider.dart'; import '../providers/page_provider.dart'; import '../providers/tasks_provider.dart'; +import 'popup_for_task_done.dart'; class ViewFormPage extends StatelessWidget { final Widget form; @@ -13,15 +13,6 @@ class ViewFormPage extends StatelessWidget { const ViewFormPage( {super.key, required this.form, required this.view, required this.page}); - void showPopup(BuildContext context) async { - AwesomeDialog( - context: context, - dialogType: DialogType.info, - title: 'Bald erst wieder', - desc: 'hier kommt ein timer hin', - ).show(); - } - @override Widget build(BuildContext context) { PageProvider pageProvider = context.watch(); @@ -35,7 +26,7 @@ class ViewFormPage extends StatelessWidget { : const Icon(Icons.add_outlined, color: Colors.black), onPressed: tasksProvider.tasks[page] ?? true ? pageProvider.swap - : () => showPopup(context), + : () => showTaskDonePopup(context, page), ), ), pageProvider.showForm