From 5b411ef6bf02f7a4deb1a6abf0c480c6baa8cf12 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 27 Feb 2023 20:02:15 +0100 Subject: [PATCH] Add AwesomeDialog --- lib/pages/main_page.dart | 14 ++++++-------- lib/providers/input_provider.dart | 4 ++-- lib/widgets/mood_form.dart | 5 ++--- lib/widgets/submit_form_button.dart | 22 +++++++++++++++++++--- pubspec.lock | 21 +++++++++++++++++++++ pubspec.yaml | 1 + 6 files changed, 51 insertions(+), 16 deletions(-) diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index f373582..7a5df4a 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -1,8 +1,8 @@ +import 'package:awesome_dialog/awesome_dialog.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/pages/pages_service.dart'; import 'package:smoke_cess_app/providers/settings_provider.dart'; -import 'package:smoke_cess_app/widgets/missing_config_popup.dart'; class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @@ -19,14 +19,12 @@ class MyHomePageState extends State { setState(() { _isConfigured ? _selectedIndex = index - : showDialog( + : AwesomeDialog( context: context, - builder: (BuildContext context) { - return const MissingConfigPopup( - title: 'Fehlende Konfiguration', - text: 'Bitte QR Code Scannen!', - ); - }); + dialogType: DialogType.info, + title: 'Fehlende Konfiguration', + desc: 'Bitte QR Code Scannen!', + ).show(); }); } diff --git a/lib/providers/input_provider.dart b/lib/providers/input_provider.dart index 5fec37c..1f4fefd 100644 --- a/lib/providers/input_provider.dart +++ b/lib/providers/input_provider.dart @@ -44,11 +44,11 @@ class InputProvider extends ChangeNotifier { notifyListeners(); } - void saveMood() { + Future saveMood() { Mood mood = Mood(_sliderValue.toInt(), _textController.text, DateTime.now()); - globals.databaseService.addMood(mood); _resetFields(); + return globals.databaseService.addMood(mood); } void saveRelapse() { diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index a997d01..b9a0e05 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -30,9 +30,8 @@ class MoodForm extends StatelessWidget { const SizedBox( height: 80, ), - ElevatedButton( - onPressed: () => inputModel.saveMood(), - child: const Text('Speichern'), + SubmitFormButton( + submitCallback: inputModel.saveMood, ) ], ); diff --git a/lib/widgets/submit_form_button.dart b/lib/widgets/submit_form_button.dart index 58f28c8..3242b18 100644 --- a/lib/widgets/submit_form_button.dart +++ b/lib/widgets/submit_form_button.dart @@ -1,15 +1,31 @@ +import 'package:awesome_dialog/awesome_dialog.dart'; import 'package:flutter/material.dart'; class SubmitFormButton extends StatelessWidget { - final VoidCallback submitCallback; - const SubmitFormButton(this.submitCallback, {super.key}); + final Future Function() submitCallback; + const SubmitFormButton({super.key, required this.submitCallback}); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.symmetric(vertical: 16.0), child: ElevatedButton( - onPressed: submitCallback, + onPressed: () async { + int success = await submitCallback(); + success != 0 + ? AwesomeDialog( + context: context, + dialogType: DialogType.success, + title: 'Gespeichert', + desc: 'Der Eintrag wurde erfolgreich gespeichert', + ).show() + : AwesomeDialog( + context: context, + dialogType: DialogType.error, + title: 'Fehler', + desc: 'Der Eintrag konnte nicht gespeichert werden', + ).show(); + }, child: const Text('Speichern'), ), ); diff --git a/pubspec.lock b/pubspec.lock index b899dd9..08b0b74 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -64,6 +64,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.3" + awesome_dialog: + dependency: "direct main" + description: + name: awesome_dialog + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" boolean_selector: dependency: transitive description: @@ -177,6 +184,13 @@ packages: description: flutter source: sdk version: "0.0.0" + graphs: + dependency: transitive + description: + name: graphs + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" http: dependency: transitive description: @@ -324,6 +338,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "6.0.5" + rive: + dependency: transitive + description: + name: rive + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.1" shared_preferences: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 9204ca9..5c61553 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: path: path_provider: ^2.0.12 provider: ^6.0.5 + awesome_dialog: ^3.0.2 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.