diff --git a/lib/main.dart b/lib/main.dart index 7da1220..47f487c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,4 @@ -import 'dart:ffi'; - import 'package:flutter/material.dart'; -import 'package:google_nav_bar/google_nav_bar.dart'; import 'package:mensaapp/providers/ambienteProvider.dart'; import 'package:mensaapp/providers/anmerkungProvider.dart'; import 'package:mensaapp/providers/essenProvider.dart'; @@ -11,8 +8,7 @@ import 'package:mensaapp/providers/serviceProvider.dart'; import 'package:mensaapp/providers/spaceProvider.dart'; import 'package:mensaapp/providers/spezielleErnaehrungProvider.dart'; import 'package:provider/provider.dart'; -import 'dart:convert'; -import 'package:flutter/services.dart' show rootBundle; +import 'dart:async'; void main() { runApp(const MyApp()); @@ -73,15 +69,95 @@ class MyApp extends StatelessWidget { } } +var lastTimeClick = DateTime.now(); + +var secondsTimeOut = 240; +var popupOpen = false; + +void _showTimeOverDialog(BuildContext context) { + popupOpen = true; + showDialog( + context: context, + builder: (context) { + return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + title: Text( + Provider.of(context, listen: false) + .languageData[Provider.of(context, listen: false).language]["general"]["timeOutTitle"], + style: TextStyle(fontSize: 25), + ), + content: Text( + Provider.of(context, listen: false) + .languageData[Provider.of(context, listen: false).language]["general"]["timeOutContent"], + style: TextStyle(fontSize: 20), + ), + actions: [ + FilledButton( + child: Text( + Provider.of(context, listen: false) + .languageData[Provider.of(context, listen: false).language]["general"]["timeOutButton"], + style: TextStyle(fontSize: 17), + ), + onPressed: () { + lastTimeClick = DateTime.now(); + popupOpen = false; + Navigator.of(context).pop(); + }, + ) + ], + ); + }, + ); +} + class MyHome extends StatelessWidget { const MyHome({super.key}); @override Widget build(BuildContext context) { - return Consumer( - builder: (context, spaceProvider, child) { - return spaceProvider.spaces[spaceProvider.selectedSpace]; - } + Timer.periodic( + const Duration(seconds: 5), + (timer) { + var clickDiff = DateTime.now().difference(lastTimeClick).inSeconds; + if (clickDiff >= secondsTimeOut && Provider.of(context, listen: false).selectedSpace == 1) { + Navigator.of(context).pop(); + Provider.of(context, listen: false) + .resetAllFields(); + Provider.of(context, listen: false) + .resetAllFields(); + Provider.of(context, listen: false) + .resetAllFields(); + Provider.of(context, listen: false) + .resetAllFields(); + Provider.of(context, listen: false) + .resetAllFields(); + Provider.of(context, listen: false) + .resetSelectedEssen(); + Provider.of(context, listen: false) + .setSelectedSpace(0); + Provider.of(context, listen: false) + .setLanguage("de"); + } else if (clickDiff >= secondsTimeOut - 30 && Provider.of(context, listen: false).selectedSpace == 1) { + if (!popupOpen) { + _showTimeOverDialog(context); + } + } + + if (Provider.of(context, listen: false).selectedSpace == 0) { + popupOpen = false; + } + }, ); + + return Consumer(builder: (context, spaceProvider, child) { + return Listener( + onPointerDown: (event) { + lastTimeClick = DateTime.now(); + }, + child: spaceProvider.spaces[spaceProvider.selectedSpace], + ); + }); } } diff --git a/lib/providers/languageProvider.dart b/lib/providers/languageProvider.dart index 0e61252..dbe6668 100644 --- a/lib/providers/languageProvider.dart +++ b/lib/providers/languageProvider.dart @@ -4,52 +4,44 @@ import 'package:flutter/services.dart'; class LanguageProvider extends ChangeNotifier { Map languageData = { - "de": - { - "textfield": "Dein Feedback", - "pageAmbiente": - { + "de": { + "general": { + "timeOutTitle": "Bist du noch da?", + "timeOutContent": "In 30 Sekunden wird deine Bewertung verworfen", + "timeOutButton": "Ich bin da!" + }, + "textfield": "Dein Feedback", + "pageAmbiente": { "question1": "Frage1", "question2": "Frage2", }, - "pageAnmerkungen": - { + "pageAnmerkungen": { "question1": "Frage1", "question2": "Frage2", }, - "pageEssen": - { + "pageEssen": { "question1": "Geschmack", "question2": "Qualität", }, - "pageHome": - { + "pageHome": { "noTimePopupTitle": "Du kannst gerade nicht bewerten!", - "noTimePopupContent": "Du kannst nur zu den Essenszeiten zwischen 11:30 und 14:30 bewerten!", + "noTimePopupContent": + "Du kannst nur zu den Essenszeiten zwischen 11:30 und 14:30 bewerten!", "noTimePopupButton": "OK" }, - "pageService": - { + "pageService": { "question1": "Frage1", "question2": "Frage2", }, - "pageSpecial": - { + "pageSpecial": { "question1": "Frage1", "question2": "Frage2", }, - "navBar": - { - "0": "Essen", - "1": "Service", - "2": "Essenswünsche" - }, - "floating": - { + "navBar": {"0": "Essen", "1": "Service", "2": "Essenswünsche"}, + "floating": { "info": "* Pflichtfeld", "return": "Absenden", - "delete": - { + "delete": { "title": "Bewertungen löschen", "info": "Möchtest du alle Eingaben entfernen?", "keep": "Behalten", @@ -57,10 +49,14 @@ class LanguageProvider extends ChangeNotifier { } } }, - "en": - { - "textfield": "Your Feedback", - "pageAmbiente": { + "en": { + "general": { + "timeOutTitle": "Are you still there?", + "timeOutContent": "Your assessment will be discarded in 30 seconds", + "timeOutButton": "I'm here!" + }, + "textfield": "Your Feedback", + "pageAmbiente": { "question1": "Question1", "question2": "Question2", }, @@ -74,7 +70,8 @@ class LanguageProvider extends ChangeNotifier { }, "pageHome": { "noTimePopupTitle": "You cannot rate right now!", - "noTimePopupContent": "You can only rate during meal times between 11:30 AM and 2:30 PM!", + "noTimePopupContent": + "You can only rate during meal times between 11:30 AM and 2:30 PM!", "noTimePopupButton": "OK" }, "pageService": { @@ -85,16 +82,11 @@ class LanguageProvider extends ChangeNotifier { "question1": "Question1", "question2": "Question2", }, - "navBar": { - "0": "Food", - "1": "Service", - "2": "Food Requests" - }, + "navBar": {"0": "Food", "1": "Service", "2": "Food Requests"}, "floating": { "info": "* Required field", "return": "Submit", - "delete": - { + "delete": { "title": "Delete Reviews", "info": "Do you want to remove all entries?", "keep": "Keep", @@ -102,10 +94,14 @@ class LanguageProvider extends ChangeNotifier { } } }, - "fr": - { - "textfield": "Votre avis", - "pageAmbiente": { + "fr": { + "general": { + "timeOutTitle": "Êtes-vous toujours là ?", + "timeOutContent": "Votre évaluation sera supprimée dans 30 secondes", + "timeOutButton": "Je suis là !" + }, + "textfield": "Votre avis", + "pageAmbiente": { "question1": "Question1", "question2": "Question2", }, @@ -119,7 +115,8 @@ class LanguageProvider extends ChangeNotifier { }, "pageHome": { "noTimePopupTitle": "Vous ne pouvez pas évaluer pour le moment !", - "noTimePopupContent": "Vous ne pouvez évaluer que pendant les heures de repas entre 11h30 et 14h30 !", + "noTimePopupContent": + "Vous ne pouvez évaluer que pendant les heures de repas entre 11h30 et 14h30 !", "noTimePopupButton": "D'ACCORD" }, "pageService": {