Implemented Views + View for avg
This commit is contained in:
+4
-1
@@ -31,7 +31,7 @@ class MyApp extends StatelessWidget {
|
||||
)
|
||||
],
|
||||
child: MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
title: 'Mensa Dashboard',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
colorScheme: const ColorScheme(
|
||||
@@ -46,6 +46,9 @@ class MyApp extends StatelessWidget {
|
||||
brightness: Brightness.light,
|
||||
tertiary: Color.fromRGBO(251, 216, 17, 1),
|
||||
onTertiary: Color.fromRGBO(60, 60, 60, 1)),
|
||||
appBarTheme: const AppBarTheme(
|
||||
iconTheme: IconThemeData(color: Color.fromRGBO(240, 240, 240, 1))
|
||||
),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHome()),
|
||||
|
||||
@@ -81,7 +81,7 @@ class BuilderToday {
|
||||
height: 20,
|
||||
),
|
||||
const Text(
|
||||
"Tagesaktuell",
|
||||
"Heute - Alle",
|
||||
style: TextStyle(fontSize: 25),
|
||||
),
|
||||
const SizedBox(
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mensaappbackend/modules/ratingCard.dart';
|
||||
|
||||
class BuilderTodayAverage {
|
||||
static Widget build(var context, var snapshot, var ratingNames) {
|
||||
var data = snapshot.data;
|
||||
|
||||
if (data == null) {
|
||||
return const Center();
|
||||
}
|
||||
|
||||
var avgs = {
|
||||
"page1": {"q1": 0.0, "q2": 0.0, "qc": 0.0},
|
||||
"page2": {"q1": 0.0, "q2": 0.0, "qc": 0.0},
|
||||
"page3": {"q1": 0.0, "q2": 0.0, "qc": 0.0}
|
||||
};
|
||||
|
||||
// sum up
|
||||
for (var map in data) {
|
||||
var ratings = map["ratings"];
|
||||
|
||||
for (var key in ratings.keys) {
|
||||
var page = ratings[key];
|
||||
|
||||
var q1 = avgs[key]!["q1"]! + page["q1"];
|
||||
var q2 = avgs[key]!["q2"]! + page["q2"];
|
||||
avgs[key]?["q1"] = q1.toDouble();
|
||||
avgs[key]?["q2"] = q2.toDouble();
|
||||
|
||||
var qc = avgs[key]!["qc"]!;
|
||||
qc += (page["q1"] == 0 ? 0 : 1);
|
||||
avgs[key]?["qc"] = qc;
|
||||
}
|
||||
}
|
||||
|
||||
// average calc
|
||||
for (var key in avgs.keys) {
|
||||
var page = avgs[key];
|
||||
|
||||
var q1 = page!["q1"]! / page["qc"]!;
|
||||
var q2 = page["q2"]! / page["qc"]!;
|
||||
|
||||
avgs[key]?["q1"] = q1;
|
||||
avgs[key]?["q2"] = q2;
|
||||
}
|
||||
|
||||
print(avgs);
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
const Text(
|
||||
"Heute - Durchschnitt",
|
||||
style: TextStyle(fontSize: 25),
|
||||
),
|
||||
const SizedBox(height: 20,),
|
||||
Wrap(
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 3))
|
||||
],
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: RatingCard(
|
||||
title: ratingNames["page1"]["title"],
|
||||
rating1Title: ratingNames["page1"]["q1"],
|
||||
rating1: avgs["page1"]!["q1"]!.toInt(),
|
||||
rating2Title: ratingNames["page1"]["q2"],
|
||||
rating2: avgs["page1"]!["q2"]!.toInt(),
|
||||
text: "",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10,),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 3))
|
||||
],
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: RatingCard(
|
||||
title: ratingNames["page2"]["title"],
|
||||
rating1Title: ratingNames["page2"]["q1"],
|
||||
rating1: avgs["page2"]!["q1"]!.toInt(),
|
||||
rating2Title: ratingNames["page2"]["q2"],
|
||||
rating2: avgs["page2"]!["q2"]!.toInt(),
|
||||
text: "",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10,),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 3))
|
||||
],
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: RatingCard(
|
||||
title: ratingNames["page3"]["title"],
|
||||
rating1Title: ratingNames["page3"]["q1"],
|
||||
rating1: avgs["page3"]!["q1"]!.toInt(),
|
||||
rating2Title: ratingNames["page3"]["q2"],
|
||||
rating2: avgs["page3"]!["q2"]!.toInt(),
|
||||
text: "",
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,11 @@ class PageDashboard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var viewDatabaseFunctions = {
|
||||
0: requestSupabaseToday,
|
||||
1: requestSupabaseToday,
|
||||
};
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
@@ -52,7 +57,7 @@ class PageDashboard extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: requestSupabaseToday(),
|
||||
future: viewDatabaseFunctions[Provider.of<ViewProvider>(context, listen: false).selectedView]!(),
|
||||
builder: (context, snapshot) {
|
||||
return Consumer<ViewProvider> (
|
||||
builder: (context, viewProvider, child) {
|
||||
@@ -61,6 +66,38 @@ class PageDashboard extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
drawer: Drawer(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 20, right: 20, top: 60),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text("Ansichten", textAlign: TextAlign.center, style: TextStyle(fontSize: 20,),),
|
||||
const SizedBox(height: 20),
|
||||
FilledButton.icon(
|
||||
style: const ButtonStyle(padding: WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 20))),
|
||||
icon: const Icon(Icons.today),
|
||||
label: const Text("Alle - Heute"),
|
||||
onPressed: () {
|
||||
Provider.of<ViewProvider>(context, listen: false).setSelectedView(0);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
FilledButton.icon(
|
||||
style: const ButtonStyle(padding: WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 20))),
|
||||
icon: const Icon(Icons.today),
|
||||
label: const Text("Durchschnitt - Heute"),
|
||||
onPressed: () {
|
||||
Provider.of<ViewProvider>(context, listen: false).setSelectedView(1);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:mensaappbackend/modules/builderToday.dart';
|
||||
import 'package:mensaappbackend/modules/builderTodayAverage.dart';
|
||||
|
||||
class ViewProvider extends ChangeNotifier {
|
||||
var selectedView = 0;
|
||||
|
||||
var views = {
|
||||
0: (context, snapshot, ratingNames) => BuilderToday.build(context, snapshot, ratingNames)
|
||||
0: (context, snapshot, ratingNames) => BuilderToday.build(context, snapshot, ratingNames),
|
||||
1: (context, snapshot, ratingNames) => BuilderTodayAverage.build(context, snapshot, ratingNames)
|
||||
};
|
||||
|
||||
void setSelectedView(var index) {
|
||||
selectedView = index;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user