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!);
}
Future<Map<String, String>> fetchGoalPinDates() async {
return await dbProvider.userQuery.subjectGoalPinDates(userId: user.id!);
}
PlanResult getResult() {
final currentAvg = GoalPlannerHelper.averageEvals(grades);
@ -369,6 +373,7 @@ class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
final goalPlans = await fetchGoalPlans();
final goalAvgs = await fetchGoalAverages();
final goalBeforeGrades = await fetchGoalBees();
final goalPinDates = await fetchGoalPinDates();
goalPlans[widget.subject.id] =
selectedRoute!.dbString;
@ -376,6 +381,8 @@ class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
goalValue.toStringAsFixed(1);
goalBeforeGrades[widget.subject.id] =
avg.toStringAsFixed(1);
goalPinDates[widget.subject.id] =
DateTime.now().toIso8601String();
await dbProvider.userStore.storeSubjectGoalPlans(
goalPlans,
@ -386,6 +393,9 @@ class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
await dbProvider.userStore.storeSubjectGoalBefores(
goalBeforeGrades,
userId: user.id!);
await dbProvider.userStore.storeSubjectGoalPinDates(
goalPinDates,
userId: user.id!);
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/progress_bar.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/route_option.dart';
import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart';
@ -36,6 +38,8 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
double beforeAvg = 0.0;
double avgDifference = 0;
Plan? plan;
late Widget gradeGraph;
DateTime goalPinDate = DateTime.now();
@ -57,6 +61,18 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
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
.where((e) => (e.subject == subject && e.date.isAfter(goalPinDate)))
.toList();
@ -69,6 +85,7 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
WidgetsBinding.instance.addPostFrameCallback((_) {
fetchGoalAverages();
fetchGoalPlan();
});
}
@ -137,10 +154,14 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
);
return Scaffold(
body: Container(
body: ListView(
padding: EdgeInsets.zero,
children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/subject_covers/math_light.png'),
image:
AssetImage('assets/images/subject_covers/math_light.png'),
fit: BoxFit.fitWidth,
alignment: Alignment.topCenter,
),
@ -161,8 +182,12 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
),
),
child: Padding(
padding: const EdgeInsets.only(top: 10.0, left: 2.0, right: 2.0),
child: ListView(
padding: const EdgeInsets.only(
top: 60.0,
left: 2.0,
right: 2.0,
),
child: Column(
children: [
const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -262,8 +287,8 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
onPressed: () async {},
fillColor: Colors.black,
shape: const StadiumBorder(),
padding:
const EdgeInsets.symmetric(horizontal: 18.0),
padding: const EdgeInsets.symmetric(
horizontal: 18.0),
child: Text(
"change_it".i18n,
style: const TextStyle(
@ -300,7 +325,8 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
.withOpacity(.15),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Icon(
FeatherIcons.chevronUp,
@ -309,7 +335,8 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
),
const SizedBox(width: 5.0),
Text(
avgDifference.toStringAsFixed(2) + '%',
avgDifference.toStringAsFixed(2) +
'%',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.greenAccent.shade700,
@ -333,11 +360,49 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
padding: const EdgeInsets.symmetric(horizontal: 12.0),
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": {
"goal_planner_title": "Goal Planning",
"almost_there": "Almost there! Keep going!",
"select_subject": "Subject",
"pick_route": "Pick a Route",
"track_it": "Track it!",
"recommended": "Recommended",
"fastest": "Fastest",
"started_with": "Started with:",
"current": "Current:",
"your_goal": "Your goal:",
"change_it": "Change it",
"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": {
"goal_planner_title": "Cél követés",
"set_a_goal": "Kitűzött cél",
"select_subject": "Tantárgy",
"pick_route": "Válassz egy utat",
"track_it": "Követés!",
"recommended": "Ajánlott",
"fastest": "Leggyorsabb",
"almost_there": "Majdnem megvan! Így tovább!",
"started_with": "Így kezdődött:",
"current": "Jelenlegi:",
"your_goal": "Célod:",
"change_it": "Megváltoztatás",
"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": {
"goal_planner_title": "Zielplanung",
"set_a_goal": "Dein Ziel",
"select_subject": "Thema",
"pick_route": "Wähle einen Weg",
"track_it": "Verfolge es!",
"recommended": "Empfohlen",
"fastest": "Am schnellsten",
"almost_there": "Fast dort! Weitermachen!",
"started_with": "Begann mit:",
"current": "Aktuell:",
"your_goal": "Dein Ziel:",
"change_it": "Ändern Sie es",
"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,
);
}
}