almost done with goal planning

This commit is contained in:
Kima 2023-08-30 23:58:55 +02:00
parent 2bd534fde9
commit 1d6b9dd5d8
4 changed files with 347 additions and 204 deletions

View File

@ -74,6 +74,10 @@ class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
return await dbProvider.userQuery.subjectGoalBefores(userId: user.id!); return await dbProvider.userQuery.subjectGoalBefores(userId: user.id!);
} }
Future<Map<String, String>> fetchGoalPinDates() async {
return await dbProvider.userQuery.subjectGoalPinDates(userId: user.id!);
}
PlanResult getResult() { PlanResult getResult() {
final currentAvg = GoalPlannerHelper.averageEvals(grades); final currentAvg = GoalPlannerHelper.averageEvals(grades);
@ -369,6 +373,7 @@ class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
final goalPlans = await fetchGoalPlans(); final goalPlans = await fetchGoalPlans();
final goalAvgs = await fetchGoalAverages(); final goalAvgs = await fetchGoalAverages();
final goalBeforeGrades = await fetchGoalBees(); final goalBeforeGrades = await fetchGoalBees();
final goalPinDates = await fetchGoalPinDates();
goalPlans[widget.subject.id] = goalPlans[widget.subject.id] =
selectedRoute!.dbString; selectedRoute!.dbString;
@ -376,6 +381,8 @@ class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
goalValue.toStringAsFixed(1); goalValue.toStringAsFixed(1);
goalBeforeGrades[widget.subject.id] = goalBeforeGrades[widget.subject.id] =
avg.toStringAsFixed(1); avg.toStringAsFixed(1);
goalPinDates[widget.subject.id] =
DateTime.now().toIso8601String();
await dbProvider.userStore.storeSubjectGoalPlans( await dbProvider.userStore.storeSubjectGoalPlans(
goalPlans, goalPlans,
@ -386,6 +393,9 @@ class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
await dbProvider.userStore.storeSubjectGoalBefores( await dbProvider.userStore.storeSubjectGoalBefores(
goalBeforeGrades, goalBeforeGrades,
userId: user.id!); userId: user.id!);
await dbProvider.userStore.storeSubjectGoalPinDates(
goalPinDates,
userId: user.id!);
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },

View File

@ -9,7 +9,9 @@ import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
import 'package:filcnaplo_mobile_ui/common/panel/panel.dart'; import 'package:filcnaplo_mobile_ui/common/panel/panel.dart';
import 'package:filcnaplo_mobile_ui/common/progress_bar.dart'; import 'package:filcnaplo_mobile_ui/common/progress_bar.dart';
import 'package:filcnaplo_mobile_ui/common/round_border_icon.dart'; import 'package:filcnaplo_mobile_ui/common/round_border_icon.dart';
import 'package:filcnaplo_premium/ui/mobile/goal_planner/goal_planner.dart';
import 'package:filcnaplo_premium/ui/mobile/goal_planner/goal_state_screen.i18n.dart'; import 'package:filcnaplo_premium/ui/mobile/goal_planner/goal_state_screen.i18n.dart';
import 'package:filcnaplo_premium/ui/mobile/goal_planner/route_option.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart'; import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -36,6 +38,8 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
double beforeAvg = 0.0; double beforeAvg = 0.0;
double avgDifference = 0; double avgDifference = 0;
Plan? plan;
late Widget gradeGraph; late Widget gradeGraph;
DateTime goalPinDate = DateTime.now(); DateTime goalPinDate = DateTime.now();
@ -57,6 +61,18 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
setState(() {}); setState(() {});
} }
void fetchGoalPlan() async {
var planRes = await db.userQuery.subjectGoalPlans(userId: user.id!);
List prePlan = planRes[widget.subject.id]!.split(',');
prePlan.removeLast();
plan = Plan(
prePlan.map((e) => int.parse(e)).toList(),
);
setState(() {});
}
List<Grade> getSubjectGrades(Subject subject) => gradeProvider.grades List<Grade> getSubjectGrades(Subject subject) => gradeProvider.grades
.where((e) => (e.subject == subject && e.date.isAfter(goalPinDate))) .where((e) => (e.subject == subject && e.date.isAfter(goalPinDate)))
.toList(); .toList();
@ -69,6 +85,7 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
fetchGoalAverages(); fetchGoalAverages();
fetchGoalPlan();
}); });
} }
@ -137,10 +154,14 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
); );
return Scaffold( return Scaffold(
body: Container( body: ListView(
padding: EdgeInsets.zero,
children: [
Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage('assets/images/subject_covers/math_light.png'), image:
AssetImage('assets/images/subject_covers/math_light.png'),
fit: BoxFit.fitWidth, fit: BoxFit.fitWidth,
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
), ),
@ -161,8 +182,12 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
), ),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.only(top: 10.0, left: 2.0, right: 2.0), padding: const EdgeInsets.only(
child: ListView( top: 60.0,
left: 2.0,
right: 2.0,
),
child: Column(
children: [ children: [
const Row( const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -262,8 +287,8 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
onPressed: () async {}, onPressed: () async {},
fillColor: Colors.black, fillColor: Colors.black,
shape: const StadiumBorder(), shape: const StadiumBorder(),
padding: padding: const EdgeInsets.symmetric(
const EdgeInsets.symmetric(horizontal: 18.0), horizontal: 18.0),
child: Text( child: Text(
"change_it".i18n, "change_it".i18n,
style: const TextStyle( style: const TextStyle(
@ -300,7 +325,8 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
.withOpacity(.15), .withOpacity(.15),
), ),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment:
CrossAxisAlignment.center,
children: [ children: [
Icon( Icon(
FeatherIcons.chevronUp, FeatherIcons.chevronUp,
@ -309,7 +335,8 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
), ),
const SizedBox(width: 5.0), const SizedBox(width: 5.0),
Text( Text(
avgDifference.toStringAsFixed(2) + '%', avgDifference.toStringAsFixed(2) +
'%',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.greenAccent.shade700, color: Colors.greenAccent.shade700,
@ -333,11 +360,49 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
padding: const EdgeInsets.symmetric(horizontal: 12.0), padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: gradeGraph, child: gradeGraph,
), ),
const SizedBox(height: 5.0),
Padding(
padding: const EdgeInsets.only(
left: 12.0,
right: 12.0,
top: 5.0,
bottom: 8.0,
),
child: Panel(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'you_need'.i18n,
style: const TextStyle(
fontSize: 23.0,
fontWeight: FontWeight.w700,
),
),
],
),
const SizedBox(height: 8.0),
plan != null
? RouteOptionRow(
plan: plan!,
)
: const Text(''),
],
),
),
),
], ],
), ),
), ),
), ),
), ),
],
),
); );
} }
} }

View File

@ -6,29 +6,38 @@ extension Localization on String {
"en_en": { "en_en": {
"goal_planner_title": "Goal Planning", "goal_planner_title": "Goal Planning",
"almost_there": "Almost there! Keep going!", "almost_there": "Almost there! Keep going!",
"select_subject": "Subject", "started_with": "Started with:",
"pick_route": "Pick a Route", "current": "Current:",
"track_it": "Track it!", "your_goal": "Your goal:",
"recommended": "Recommended", "change_it": "Change it",
"fastest": "Fastest", "look_at_graph": "Look at this graph!",
"thats_progress":
"Now that's what I call progress! Push a little more, you're almost there..",
"you_need": "You need:",
}, },
"hu_hu": { "hu_hu": {
"goal_planner_title": "Cél követés", "goal_planner_title": "Cél követés",
"set_a_goal": "Kitűzött cél", "almost_there": "Majdnem megvan! Így tovább!",
"select_subject": "Tantárgy", "started_with": "Így kezdődött:",
"pick_route": "Válassz egy utat", "current": "Jelenlegi:",
"track_it": "Követés!", "your_goal": "Célod:",
"recommended": "Ajánlott", "change_it": "Megváltoztatás",
"fastest": "Leggyorsabb", "look_at_graph": "Nézd meg ezt a grafikont!",
"thats_progress":
"Ezt nevezem haladásnak! Hajts még egy kicsit, már majdnem kész..",
"you_need": "Szükséges:",
}, },
"de_de": { "de_de": {
"goal_planner_title": "Zielplanung", "goal_planner_title": "Zielplanung",
"set_a_goal": "Dein Ziel", "almost_there": "Fast dort! Weitermachen!",
"select_subject": "Thema", "started_with": "Begann mit:",
"pick_route": "Wähle einen Weg", "current": "Aktuell:",
"track_it": "Verfolge es!", "your_goal": "Dein Ziel:",
"recommended": "Empfohlen", "change_it": "Ändern Sie es",
"fastest": "Am schnellsten", "look_at_graph": "Schauen Sie sich diese Grafik an!",
"thats_progress":
"Das nenne ich Fortschritt! Drücken Sie noch ein wenig, Sie haben es fast geschafft..",
"you_need": "Du brauchst:",
}, },
}; };

View File

@ -141,3 +141,62 @@ class RouteOption extends StatelessWidget {
); );
} }
} }
class RouteOptionRow extends StatelessWidget {
const RouteOptionRow({
Key? key,
required this.plan,
this.mark,
}) : super(key: key);
final Plan plan;
final RouteMark? mark;
@override
Widget build(BuildContext context) {
List<Widget> gradeWidgets = [];
for (int i = 5; i > 1; i--) {
final count = plan.plan.where((e) => e == i).length;
if (count > 4) {
gradeWidgets.add(Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"${count}x",
style: TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.w500,
color: AppColors.of(context).text.withOpacity(.7),
),
),
const SizedBox(width: 4.0),
GradeDisplay(grade: i),
],
));
} else {
gradeWidgets
.addAll(List.generate(count, (_) => GradeDisplay(grade: i)));
}
if (count > 0) {
gradeWidgets.add(SizedBox(
height: 36.0,
width: 32.0,
child: Center(
child: Icon(Icons.add,
color: AppColors.of(context).text.withOpacity(.5))),
));
}
}
gradeWidgets.removeLast();
return Wrap(
spacing: 4.0,
runSpacing: 8.0,
children: gradeWidgets,
);
}
}