Giga Push (it is 1:30 am and I am tired)
Backend Structure implemented All Ratings will be pulled and validated Pop Up notfies user about all his ratings If confirmed, data will be send to the supabase server (if any data was found) No comments were made, who else needs to read this?
This commit is contained in:
+23
-3
@@ -9,8 +9,25 @@ import 'package:mensaapp/providers/spaceProvider.dart';
|
||||
import 'package:mensaapp/providers/spezielleErnaehrungProvider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'dart:async';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await Supabase.initialize(
|
||||
url: "http://192.168.2.229:8000",
|
||||
anonKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE",
|
||||
);
|
||||
|
||||
var supabase = Supabase.instance.client;
|
||||
|
||||
/*
|
||||
var test = await supabase.from('flutter').insert(
|
||||
{"rating": {"huhu" : "Fuuuuck uuuuuu if this works"}}
|
||||
);
|
||||
*/
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
@@ -71,7 +88,7 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
var lastTimeClick = DateTime.now();
|
||||
|
||||
var secondsTimeOut = 80;
|
||||
var secondsTimeOut = 80; //80
|
||||
var popupOpen = false;
|
||||
|
||||
void _showTimeOverDialog(BuildContext context) {
|
||||
@@ -122,7 +139,7 @@ class MyHome extends StatelessWidget {
|
||||
(timer) {
|
||||
var clickDiff = DateTime.now().difference(lastTimeClick).inSeconds;
|
||||
if (clickDiff >= secondsTimeOut && Provider.of<SpaceProvider>(context, listen: false).selectedSpace == 1) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
Provider.of<AnmerkungProvider>(context, listen: false)
|
||||
.resetAllFields();
|
||||
Provider.of<EssenProvider>(context, listen: false)
|
||||
@@ -135,6 +152,8 @@ class MyHome extends StatelessWidget {
|
||||
.resetAllFields();
|
||||
Provider.of<PageProvider>(context, listen: false)
|
||||
.resetSelectedEssen();
|
||||
Provider.of<PageProvider>(context, listen: false)
|
||||
.changePage(0);
|
||||
Provider.of<SpaceProvider>(context, listen: false)
|
||||
.setSelectedSpace(0);
|
||||
Provider.of<LanguageProvider>(context, listen: false)
|
||||
@@ -142,6 +161,7 @@ class MyHome extends StatelessWidget {
|
||||
} else if (clickDiff >= secondsTimeOut - 30 && Provider.of<SpaceProvider>(context, listen: false).selectedSpace == 1) {
|
||||
if (!popupOpen) {
|
||||
_showTimeOverDialog(context);
|
||||
_showTimeOverDialog(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:mensaapp/providers/spezielleErnaehrungProvider.dart';
|
||||
import 'package:mensaapp/providers/serviceProvider.dart';
|
||||
import 'package:mensaapp/providers/ambienteProvider.dart';
|
||||
import 'package:mensaapp/providers/anmerkungProvider.dart';
|
||||
import 'package:mensaapp/providers/essenProvider.dart';
|
||||
import '../providers/pageProvider.dart';
|
||||
import '../providers/languageProvider.dart';
|
||||
import 'package:mensaapp/providers/spaceProvider.dart';
|
||||
|
||||
|
||||
class DatabaseService {
|
||||
final SupabaseClient supabase = Supabase.instance.client;
|
||||
|
||||
void getAllRatings(BuildContext context) {
|
||||
var serviceProvider = Provider.of<ServiceProvider>(context, listen: false);
|
||||
var essenProvider = Provider.of<EssenProvider>(context, listen: false);
|
||||
var speziellerProvider = Provider.of<SpezielleErnaehrungProvider>(context, listen: false);
|
||||
var pageProvider = Provider.of<PageProvider>(context, listen: false);
|
||||
|
||||
var essenData = {
|
||||
"q1": essenProvider.ratingQuali,
|
||||
"q2": essenProvider.ratingGeschmack,
|
||||
"t1": essenProvider.freiText,
|
||||
"food": pageProvider.selectedEssenName
|
||||
};
|
||||
|
||||
var serviceData = {
|
||||
"q1": serviceProvider.ratingFrage1,
|
||||
"q2": serviceProvider.ratingFrage2,
|
||||
"t1": serviceProvider.freiText
|
||||
};
|
||||
|
||||
var speziellerData = {
|
||||
"q1": speziellerProvider.frage1,
|
||||
"q2": speziellerProvider.frage2,
|
||||
"t1": speziellerProvider.freiText
|
||||
};
|
||||
|
||||
var sendData = {
|
||||
"page1": {
|
||||
"q1": 0,
|
||||
"q2": 0,
|
||||
"t1": "",
|
||||
"food": ""
|
||||
},
|
||||
"page2": {
|
||||
"q1": 0,
|
||||
"q2": 0,
|
||||
"t1": ""
|
||||
},
|
||||
"page3": {
|
||||
"q1": 0,
|
||||
"q2": 0,
|
||||
"t1": ""
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var jsonArray = [serviceData, essenData, speziellerData];
|
||||
|
||||
for (var element in jsonArray) {
|
||||
var exists = checkIfRatingExists(element);
|
||||
if (exists) {
|
||||
if (element == essenData) {
|
||||
sendData["page1"] = element;
|
||||
} else if (element == serviceData) {
|
||||
sendData["page2"] = element;
|
||||
} else if (element == speziellerData) {
|
||||
sendData["page3"] = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
print(sendData);
|
||||
_showConfirmationDialog(context, sendData);
|
||||
|
||||
}
|
||||
|
||||
bool checkIfRatingExists(Map<String, dynamic> myJson) {
|
||||
return !myJson.values.any((value) => value == 0);
|
||||
}
|
||||
|
||||
Future<void> sendDataToSupabase(Map<String, dynamic> data) async {
|
||||
try {
|
||||
final response = await supabase.from('flutter').insert({"rating": data});
|
||||
print("Antwort von Supabase: $response");
|
||||
|
||||
if (response == null) {
|
||||
throw Exception("Antwort von Supabase ist null");
|
||||
}
|
||||
|
||||
if (response['error'] != null) {
|
||||
throw Exception("Supabase-Fehler: ${response['error']}");
|
||||
}
|
||||
|
||||
print("Daten erfolgreich gesendet: ${response['data']}");
|
||||
} catch (error) { //vielleicht überarbeiten? Pop Up mit "Admin verständigen"
|
||||
print("Fehler beim Senden der Daten: $error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _showConfirmationDialog(BuildContext context, data) {
|
||||
String formatData(Map<String, dynamic> pageData, String title) {
|
||||
if (pageData['q1'] != 0 && pageData['q2'] != 0) {
|
||||
String foodLine = pageData.containsKey('food') ? "- ${pageData['food']}\n" : "";
|
||||
return "$title:\n"
|
||||
"$foodLine"
|
||||
"- Frage 1: ${pageData['q1'].toInt()}/5 Sterne\n"
|
||||
"- Frage 2: ${pageData['q2'].toInt()}/5 Sterne\n"
|
||||
"- Freitext: ${pageData['t1']}\n\n";
|
||||
}
|
||||
return "$title: Nicht bewertet\n\n";
|
||||
}
|
||||
|
||||
bool allUnrated = data.values.every((pageData) => pageData['q1'] == 0 && pageData['q2'] == 0 && (pageData['t1'] ?? "").isEmpty);
|
||||
|
||||
String dialogContent =
|
||||
formatData(data["page1"], "Essen") +
|
||||
formatData(data["page2"], "Service") +
|
||||
formatData(data["page3"], "Spezielle Nahrung");
|
||||
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext dialogContext) {
|
||||
return AlertDialog(
|
||||
title: Text("Bestätigung"),
|
||||
content: SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.6,
|
||||
height: MediaQuery.of(context).size.height * 0.3,
|
||||
child: SingleChildScrollView(
|
||||
child: Text(
|
||||
dialogContent,
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(dialogContext).pop(); // Abbrechen
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.secondary),
|
||||
child: Text("Abbrechen"),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: allUnrated
|
||||
? null // Button deaktivieren
|
||||
: () async {
|
||||
Navigator.of(dialogContext).pop(); // Dialog schließen
|
||||
await sendDataToSupabase(data);
|
||||
Provider.of<EssenProvider>(context, listen: false).resetAllFields();
|
||||
Provider.of<ServiceProvider>(context, listen: false).resetAllFields();
|
||||
Provider.of<SpezielleErnaehrungProvider>(context, listen: false)
|
||||
.resetAllFields();
|
||||
Provider.of<PageProvider>(context, listen: false).resetSelectedEssen();
|
||||
Provider.of<SpaceProvider>(context, listen: false).setSelectedSpace(0);
|
||||
Provider.of<LanguageProvider>(context, listen: false).setLanguage("de");
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: allUnrated
|
||||
? Colors.grey // Button farblich anzeigen, wenn deaktiviert
|
||||
: Theme.of(context).primaryColor,
|
||||
),
|
||||
child: Text("Absenden",
|
||||
style: TextStyle(
|
||||
decoration: allUnrated ? TextDecoration.lineThrough : null,
|
||||
color: allUnrated ? Colors.black54 : Theme.of(context).colorScheme.secondary)
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ class PageSpezielleErnaehrung extends StatelessWidget {
|
||||
return RatingStars(
|
||||
onRate: (value) {
|
||||
spezielleErnaehrungProvider
|
||||
.setRatingSitzmoeglichkeit(value);
|
||||
.setRatingFrage1(value);
|
||||
},
|
||||
initRating: spezielleErnaehrungProvider
|
||||
.ratingSitzmoeglichkeit,
|
||||
.frage1,
|
||||
);
|
||||
},
|
||||
)
|
||||
@@ -85,10 +85,10 @@ class PageSpezielleErnaehrung extends StatelessWidget {
|
||||
return RatingStars(
|
||||
onRate: (value) {
|
||||
spezielleErnaehrungProvider
|
||||
.setRatingKeineAhnung(value);
|
||||
.setRatingFrage2(value);
|
||||
},
|
||||
initRating:
|
||||
spezielleErnaehrungProvider.ratingKeineAhnung,
|
||||
spezielleErnaehrungProvider.frage2,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -12,16 +12,16 @@ class LanguageProvider extends ChangeNotifier {
|
||||
},
|
||||
"textfield": "Dein Feedback",
|
||||
"pageAmbiente": {
|
||||
"question1": "Frage1",
|
||||
"question2": "Frage2",
|
||||
"question1": "Frage1*",
|
||||
"question2": "Frage2*",
|
||||
},
|
||||
"pageAnmerkungen": {
|
||||
"question1": "Frage1",
|
||||
"question2": "Frage2",
|
||||
"question1": "Frage1*",
|
||||
"question2": "Frage2*",
|
||||
},
|
||||
"pageEssen": {
|
||||
"question1": "Geschmack",
|
||||
"question2": "Qualität",
|
||||
"question1": "Geschmack*",
|
||||
"question2": "Qualität*",
|
||||
},
|
||||
"pageHome": {
|
||||
"noTimePopupTitle": "Du kannst gerade nicht bewerten!",
|
||||
@@ -30,12 +30,12 @@ class LanguageProvider extends ChangeNotifier {
|
||||
"noTimePopupButton": "OK"
|
||||
},
|
||||
"pageService": {
|
||||
"question1": "Frage1",
|
||||
"question2": "Frage2",
|
||||
"question1": "Frage1*",
|
||||
"question2": "Frage2*",
|
||||
},
|
||||
"pageSpecial": {
|
||||
"question1": "Frage1",
|
||||
"question2": "Frage2",
|
||||
"question1": "Frage1*",
|
||||
"question2": "Frage2*",
|
||||
},
|
||||
"navBar": {"0": "Essen", "1": "Service", "2": "Essenswünsche"},
|
||||
"floating": {
|
||||
@@ -57,16 +57,16 @@ class LanguageProvider extends ChangeNotifier {
|
||||
},
|
||||
"textfield": "Your Feedback",
|
||||
"pageAmbiente": {
|
||||
"question1": "Question1",
|
||||
"question2": "Question2",
|
||||
"question1": "Question1*",
|
||||
"question2": "Question2*",
|
||||
},
|
||||
"pageAnmerkungen": {
|
||||
"question1": "Question1",
|
||||
"question2": "Question2",
|
||||
"question1": "Question1*",
|
||||
"question2": "Question2*",
|
||||
},
|
||||
"pageEssen": {
|
||||
"question1": "Taste",
|
||||
"question2": "Quality",
|
||||
"question1": "Taste*",
|
||||
"question2": "Quality*",
|
||||
},
|
||||
"pageHome": {
|
||||
"noTimePopupTitle": "You cannot rate right now!",
|
||||
@@ -75,12 +75,12 @@ class LanguageProvider extends ChangeNotifier {
|
||||
"noTimePopupButton": "OK"
|
||||
},
|
||||
"pageService": {
|
||||
"question1": "Question1",
|
||||
"question2": "Question2",
|
||||
"question1": "Question1*",
|
||||
"question2": "Question2*",
|
||||
},
|
||||
"pageSpecial": {
|
||||
"question1": "Question1",
|
||||
"question2": "Question2",
|
||||
"question1": "Question1*",
|
||||
"question2": "Question2*",
|
||||
},
|
||||
"navBar": {"0": "Food", "1": "Service", "2": "Food Requests"},
|
||||
"floating": {
|
||||
@@ -102,16 +102,16 @@ class LanguageProvider extends ChangeNotifier {
|
||||
},
|
||||
"textfield": "Votre avis",
|
||||
"pageAmbiente": {
|
||||
"question1": "Question1",
|
||||
"question2": "Question2",
|
||||
"question1": "Question1*",
|
||||
"question2": "Question2*",
|
||||
},
|
||||
"pageAnmerkungen": {
|
||||
"question1": "Question1",
|
||||
"question2": "Question2",
|
||||
"question1": "Question1*",
|
||||
"question2": "Question2*",
|
||||
},
|
||||
"pageEssen": {
|
||||
"question1": "Goût",
|
||||
"question2": "Qualité",
|
||||
"question1": "Goût*",
|
||||
"question2": "Qualité*",
|
||||
},
|
||||
"pageHome": {
|
||||
"noTimePopupTitle": "Vous ne pouvez pas évaluer pour le moment !",
|
||||
@@ -120,12 +120,12 @@ class LanguageProvider extends ChangeNotifier {
|
||||
"noTimePopupButton": "D'ACCORD"
|
||||
},
|
||||
"pageService": {
|
||||
"question1": "Question1",
|
||||
"question2": "Question2",
|
||||
"question1": "Question1*",
|
||||
"question2": "Question2*",
|
||||
},
|
||||
"pageSpecial": {
|
||||
"question1": "Question1",
|
||||
"question2": "Question2",
|
||||
"question1": "Question1*",
|
||||
"question2": "Question2*",
|
||||
},
|
||||
"navBar": {
|
||||
"0": "Nourriture",
|
||||
|
||||
@@ -2,17 +2,17 @@ import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class SpezielleErnaehrungProvider extends ChangeNotifier {
|
||||
double ratingSitzmoeglichkeit = 0;
|
||||
double ratingKeineAhnung = 0;
|
||||
double frage1 = 0;
|
||||
double frage2 = 0;
|
||||
String freiText = "";
|
||||
|
||||
void setRatingSitzmoeglichkeit(double rating) {
|
||||
ratingSitzmoeglichkeit = rating;
|
||||
void setRatingFrage1(double rating) {
|
||||
frage1 = rating;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setRatingKeineAhnung(double rating) {
|
||||
ratingKeineAhnung = rating;
|
||||
void setRatingFrage2(double rating) {
|
||||
frage2 = rating;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ class SpezielleErnaehrungProvider extends ChangeNotifier {
|
||||
|
||||
void resetAllFields(){
|
||||
freiText = "";
|
||||
ratingSitzmoeglichkeit = 0;
|
||||
ratingKeineAhnung = 0;
|
||||
frage1 = 0;
|
||||
frage2 = 0;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class _SpaceHomeState extends State<SpaceHome> {
|
||||
}
|
||||
|
||||
// only for test
|
||||
var disableRateTimeDebug = false;
|
||||
var disableRateTimeDebug = true;
|
||||
|
||||
// end only for test
|
||||
void _showNotRateTimeDialog(BuildContext context) {
|
||||
@@ -138,6 +138,7 @@ class _SpaceHomeState extends State<SpaceHome> {
|
||||
children: [
|
||||
Text(
|
||||
text,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 70,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_nav_bar/google_nav_bar.dart';
|
||||
import 'package:mensaapp/modules/databaseService.dart';
|
||||
import 'package:mensaapp/providers/spaceProvider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -46,18 +47,20 @@ class SpaceRate extends StatelessWidget {
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Provider.of<AnmerkungProvider>(context, listen: false)
|
||||
.resetAllFields();
|
||||
/*Provider.of<AnmerkungProvider>(context, listen: false)
|
||||
.resetAllFields();*/
|
||||
Provider.of<EssenProvider>(context, listen: false)
|
||||
.resetAllFields();
|
||||
Provider.of<AmbienteProvider>(context, listen: false)
|
||||
.resetAllFields();
|
||||
/*Provider.of<AmbienteProvider>(context, listen: false)
|
||||
.resetAllFields();*/
|
||||
Provider.of<ServiceProvider>(context, listen: false)
|
||||
.resetAllFields();
|
||||
Provider.of<SpezielleErnaehrungProvider>(context, listen: false)
|
||||
.resetAllFields();
|
||||
Provider.of<PageProvider>(context, listen: false)
|
||||
.resetSelectedEssen();
|
||||
Provider.of<PageProvider>(context, listen: false)
|
||||
.changePage(0);
|
||||
Provider.of<SpaceProvider>(context, listen: false)
|
||||
.setSelectedSpace(0);
|
||||
Provider.of<LanguageProvider>(context, listen: false)
|
||||
@@ -213,7 +216,15 @@ class SpaceRate extends StatelessWidget {
|
||||
height: 10,
|
||||
),
|
||||
FloatingActionButton.extended(
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
DatabaseService().getAllRatings(
|
||||
context
|
||||
);
|
||||
|
||||
/*DatabaseService.getAllRatings(
|
||||
Provider.of<ServiceProvider>(context), Provider.of<EssenProvider>(context), Provider.of<SpezielleErnaehrungProvider>(context)); // Passe den Kontext an, falls nötig
|
||||
*/
|
||||
},
|
||||
label: Text(
|
||||
Provider.of<LanguageProvider>(context).languageData[
|
||||
Provider.of<LanguageProvider>(context).language]
|
||||
|
||||
Reference in New Issue
Block a user