163 lines
5.2 KiB
Dart
163 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mensaappbackend/modules/ratingCard.dart';
|
|
import 'package:mensaappbackend/providers/timeProvider.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class BuilderAverage {
|
|
static Widget build(var context, var snapshot, var ratingNames) {
|
|
var data = snapshot.data;
|
|
|
|
Map<String, Map> dic = {
|
|
"page1": {},
|
|
"page2": {"q1": 0, "q2": 0, "avg_q1": 0, "avg_q2": 0, "counter": 0},
|
|
"page3": {"q1": 0, "q2": 0, "avg_q1": 0, "avg_q2": 0, "counter": 0}
|
|
};
|
|
|
|
for (Map bewertung in data) {
|
|
for (var page in bewertung["ratings"].keys) {
|
|
var tmp_dic = bewertung["ratings"][page];
|
|
switch (page) {
|
|
case "page1":
|
|
var curKey = tmp_dic["food"].split(": ")[1];
|
|
if (!dic["page1"]!.containsKey(curKey)) {
|
|
dic["page1"]![curKey] = {
|
|
"q1": 0,
|
|
"q2": 0,
|
|
"avg_q1": 0,
|
|
"avg_q2": 0,
|
|
"counter": 0
|
|
};
|
|
}
|
|
dic["page1"]![curKey]["q1"] += tmp_dic["q1"];
|
|
dic["page1"]![curKey]["q2"] += tmp_dic["q2"];
|
|
dic["page1"]![curKey]["counter"] += tmp_dic["q1"] == 0 ? 0 : 1;
|
|
break;
|
|
|
|
case "page2":
|
|
dic["page2"]!["q1"] += tmp_dic["q1"];
|
|
dic["page2"]!["q2"] += tmp_dic["q2"];
|
|
dic["page2"]!["counter"] += tmp_dic["q1"] == 0 ? 0 : 1;
|
|
break;
|
|
|
|
case "page3":
|
|
dic["page3"]!["q1"] += tmp_dic["q1"];
|
|
dic["page3"]!["q2"] += tmp_dic["q2"];
|
|
dic["page3"]!["counter"] += tmp_dic["q1"] == 0 ? 0 : 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Map finalDic = {};
|
|
|
|
if (dic["page2"]!["q1"] != 0) {
|
|
finalDic["Service"] = {"org": "page2", "q1": 0, "q2": 0};
|
|
finalDic["Service"]!["q1"] = (dic["page2"]!["q1"] / dic["page2"]!["counter"]).round().toInt();
|
|
finalDic["Service"]!["q2"] = (dic["page2"]!["q2"] / dic["page2"]!["counter"]).round().toInt();
|
|
}
|
|
|
|
if (dic["page3"]!["q2"] != 0) {
|
|
finalDic["Essenswünsche"] = {"org": "page3", "q1": 0, "q2": 0};
|
|
finalDic["Essenswünsche"]!["q1"] = (dic["page3"]!["q1"] / dic["page3"]!["counter"]).round().toInt();
|
|
finalDic["Essenswünsche"]!["q2"] = (dic["page3"]!["q2"] / dic["page3"]!["counter"]).round().toInt();
|
|
}
|
|
|
|
for (var food in dic["page1"]!.keys) {
|
|
var foodData = dic["page1"]![food];
|
|
finalDic[food] = {"q1": 0, "q2": 0, "org": "page1"};
|
|
finalDic[food]["q1"] = (foodData["q1"] / foodData["counter"]).round().toInt();
|
|
finalDic[food]?["q2"] = (foodData["q2"] / foodData["counter"]).round().toInt();
|
|
}
|
|
|
|
List<Widget> cards = [];
|
|
|
|
if (data == null) {
|
|
return const Center();
|
|
}
|
|
|
|
for (var title in finalDic.keys) {
|
|
List<Widget> children = [];
|
|
var rating = finalDic[title];
|
|
|
|
if (rating["q1"] != 0) {
|
|
Widget card = RatingCard(
|
|
rating1: rating["q1"],
|
|
rating2: rating["q2"],
|
|
text: "",
|
|
title: title,
|
|
rating1Title: ratingNames[rating["org"]]!["q1"]!,
|
|
rating2Title: ratingNames[rating["org"]]!["q2"]!,
|
|
);
|
|
children.add(card);
|
|
children.add(const SizedBox(
|
|
width: 10,
|
|
));
|
|
}
|
|
|
|
cards.add(Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(15),
|
|
decoration: BoxDecoration(
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.8),
|
|
spreadRadius: 0,
|
|
blurRadius: 0,
|
|
offset: const Offset(0, 0))
|
|
],
|
|
borderRadius: BorderRadius.circular(15),
|
|
color: Theme.of(context).colorScheme.surface.withOpacity(0.8)),
|
|
child: Column(
|
|
children: [
|
|
Wrap(
|
|
runAlignment: WrapAlignment.center,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
runSpacing: 10,
|
|
children: children,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 15,
|
|
),
|
|
],
|
|
));
|
|
}
|
|
|
|
return Center(
|
|
child: IntrinsicWidth(
|
|
stepWidth: 2,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
Consumer<TimeProvider>(
|
|
builder: (context, timeProvider, child) {
|
|
// Dynamischer Text basierend auf TimeProvider
|
|
String text =
|
|
timeProvider.timeList[timeProvider.selectedTime]!;
|
|
return Text(
|
|
text + " - Durchschnitt",
|
|
style: const TextStyle(fontSize: 25),
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
for (var card in cards) card,
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|