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?
184 lines
6.2 KiB
Dart
184 lines
6.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mensaapp/providers/ambienteProvider.dart';
|
|
import 'package:mensaapp/providers/anmerkungProvider.dart';
|
|
import 'package:mensaapp/providers/essenProvider.dart';
|
|
import 'package:mensaapp/providers/languageProvider.dart';
|
|
import 'package:mensaapp/providers/pageProvider.dart';
|
|
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: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"}}
|
|
);
|
|
*/
|
|
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider(
|
|
create: (context) => PageProvider(),
|
|
),
|
|
ChangeNotifierProvider(
|
|
create: (context) => EssenProvider(),
|
|
),
|
|
ChangeNotifierProvider(
|
|
create: (context) => ServiceProvider(),
|
|
),
|
|
ChangeNotifierProvider(
|
|
create: (context) => AmbienteProvider(),
|
|
),
|
|
ChangeNotifierProvider(
|
|
create: (context) => AnmerkungProvider(),
|
|
),
|
|
ChangeNotifierProvider(
|
|
create: (context) => SpezielleErnaehrungProvider(),
|
|
),
|
|
ChangeNotifierProvider(
|
|
create: (context) => LanguageProvider(),
|
|
),
|
|
ChangeNotifierProvider(
|
|
create: (context) => SpaceProvider(),
|
|
)
|
|
],
|
|
child: MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
colorScheme: const ColorScheme(
|
|
primary: Color.fromRGBO(236, 92, 61, 1),
|
|
onPrimary: Color.fromRGBO(240, 240, 240, 1),
|
|
secondary: Color.fromRGBO(203, 203, 203, 1),
|
|
onSecondary: Color.fromRGBO(60, 60, 60, 1),
|
|
error: Colors.red,
|
|
onError: Colors.white,
|
|
surface: Colors.white,
|
|
onSurface: Color.fromRGBO(60, 60, 60, 1),
|
|
brightness: Brightness.light,
|
|
tertiary: Color.fromRGBO(251, 216, 17, 1),
|
|
onTertiary: Color.fromRGBO(60, 60, 60, 1)),
|
|
useMaterial3: true,
|
|
),
|
|
home: const MyHome()),
|
|
);
|
|
}
|
|
}
|
|
|
|
var lastTimeClick = DateTime.now();
|
|
|
|
var secondsTimeOut = 80; //80
|
|
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<LanguageProvider>(context, listen: false)
|
|
.languageData[Provider.of<LanguageProvider>(context, listen: false).language]["general"]["timeOutTitle"],
|
|
style: TextStyle(fontSize: 25),
|
|
),
|
|
content: Text(
|
|
Provider.of<LanguageProvider>(context, listen: false)
|
|
.languageData[Provider.of<LanguageProvider>(context, listen: false).language]["general"]["timeOutContent"],
|
|
style: TextStyle(fontSize: 20),
|
|
),
|
|
actions: [
|
|
FilledButton(
|
|
child: Text(
|
|
Provider.of<LanguageProvider>(context, listen: false)
|
|
.languageData[Provider.of<LanguageProvider>(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) {
|
|
Timer.periodic(
|
|
const Duration(seconds: 5),
|
|
(timer) {
|
|
var clickDiff = DateTime.now().difference(lastTimeClick).inSeconds;
|
|
if (clickDiff >= secondsTimeOut && Provider.of<SpaceProvider>(context, listen: false).selectedSpace == 1) {
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
|
Provider.of<AnmerkungProvider>(context, listen: false)
|
|
.resetAllFields();
|
|
Provider.of<EssenProvider>(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)
|
|
.setLanguage("de");
|
|
} else if (clickDiff >= secondsTimeOut - 30 && Provider.of<SpaceProvider>(context, listen: false).selectedSpace == 1) {
|
|
if (!popupOpen) {
|
|
_showTimeOverDialog(context);
|
|
_showTimeOverDialog(context);
|
|
}
|
|
}
|
|
|
|
if (Provider.of<SpaceProvider>(context, listen: false).selectedSpace == 0) {
|
|
popupOpen = false;
|
|
}
|
|
},
|
|
);
|
|
|
|
return Consumer<SpaceProvider>(builder: (context, spaceProvider, child) {
|
|
return Listener(
|
|
onPointerDown: (event) {
|
|
lastTimeClick = DateTime.now();
|
|
},
|
|
child: spaceProvider.spaces[spaceProvider.selectedSpace],
|
|
);
|
|
});
|
|
}
|
|
}
|