init refilc-plus
This commit is contained in:
commit
6edc2029bd
37 changed files with 6988 additions and 0 deletions
253
lib/ui/mobile/goal_planner/goal_complete_modal.dart
Normal file
253
lib/ui/mobile/goal_planner/goal_complete_modal.dart
Normal file
|
@ -0,0 +1,253 @@
|
|||
import 'package:refilc/api/providers/database_provider.dart';
|
||||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_kreta_api/models/subject.dart';
|
||||
import 'package:refilc_mobile_ui/common/average_display.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_state_screen.i18n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GoalCompleteModal extends StatelessWidget {
|
||||
const GoalCompleteModal(
|
||||
this.subject, {
|
||||
super.key,
|
||||
required this.user,
|
||||
required this.database,
|
||||
required this.goalAverage,
|
||||
required this.beforeAverage,
|
||||
required this.averageDifference,
|
||||
});
|
||||
|
||||
final UserProvider user;
|
||||
final DatabaseProvider database;
|
||||
final GradeSubject subject;
|
||||
|
||||
final double goalAverage;
|
||||
final double beforeAverage;
|
||||
final double averageDifference;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dialog(
|
||||
elevation: 0,
|
||||
backgroundColor: Colors.transparent,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
image: const DecorationImage(
|
||||
image: AssetImage('assets/images/static_confetti.png'),
|
||||
fit: BoxFit.fitWidth,
|
||||
alignment: Alignment.topCenter,
|
||||
),
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
goalAverage.toStringAsFixed(1),
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 64.0,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
// const SizedBox(width: 10.0),
|
||||
// Icon(
|
||||
// SubjectIcon.resolveVariant(
|
||||
// subject: subject, context: context),
|
||||
// color: Colors.white,
|
||||
// size: 64.0,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Text(
|
||||
'congrats_title'.i18n,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 27.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
height: 1.2,
|
||||
color: AppColors.of(context).text,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'goal_reached'.i18n.fill(['20']),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.1,
|
||||
color: AppColors.of(context).text,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 18.0),
|
||||
Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'started_at'.i18n,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 17.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.of(context).text,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5.0),
|
||||
AverageDisplay(
|
||||
average: beforeAverage,
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
'improved_by'.i18n.fill([
|
||||
'${averageDifference.toStringAsFixed(2)}%',
|
||||
]),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 17.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.of(context).text,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
Column(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("Hamarosan...")),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
gradient: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFFCAECFA),
|
||||
Color(0xFFF4D9EE),
|
||||
Color(0xFFF3EFDA),
|
||||
],
|
||||
stops: [0.0, 0.53, 1.0],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(
|
||||
'detailed_stats'.i18n,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 18.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Color(0xFF691A9B),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
color: const Color.fromARGB(38, 131, 131, 131),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(
|
||||
'later'.i18n,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 18.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.of(context).text,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// return Padding(
|
||||
// padding: const EdgeInsets.symmetric(vertical: 100.0, horizontal: 32.0),
|
||||
// child: Material(
|
||||
// borderRadius: BorderRadius.circular(12.0),
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.all(12.0),
|
||||
// child: Column(
|
||||
// children: [
|
||||
// // content or idk
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
}
|
||||
|
||||
static Future<T?> show<T>(
|
||||
GradeSubject subject, {
|
||||
required BuildContext context,
|
||||
}) async {
|
||||
UserProvider user = Provider.of<UserProvider>(context, listen: false);
|
||||
DatabaseProvider db = Provider.of<DatabaseProvider>(context, listen: false);
|
||||
|
||||
var goalAvgRes = await db.userQuery.subjectGoalAverages(userId: user.id!);
|
||||
var beforeAvgRes = await db.userQuery.subjectGoalBefores(userId: user.id!);
|
||||
|
||||
//DateTime goalPinDate = DateTime.parse((await db.userQuery.subjectGoalPinDates(userId: user.id!))[widget.subject.id]!);
|
||||
|
||||
String? goalAvgStr = goalAvgRes[subject.id];
|
||||
String? beforeAvgStr = beforeAvgRes[subject.id];
|
||||
double goalAvg = double.parse(goalAvgStr ?? '0.0');
|
||||
double beforeAvg = double.parse(beforeAvgStr ?? '0.0');
|
||||
|
||||
double avgDifference = ((goalAvg - beforeAvg) / beforeAvg.abs()) * 100;
|
||||
|
||||
return showDialog<T?>(
|
||||
// ignore: use_build_context_synchronously
|
||||
context: context,
|
||||
builder: (context) => GoalCompleteModal(
|
||||
subject,
|
||||
user: user,
|
||||
database: db,
|
||||
goalAverage: goalAvg,
|
||||
beforeAverage: beforeAvg,
|
||||
averageDifference: avgDifference,
|
||||
),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
}
|
||||
}
|
204
lib/ui/mobile/goal_planner/goal_input.dart
Normal file
204
lib/ui/mobile/goal_planner/goal_input.dart
Normal file
|
@ -0,0 +1,204 @@
|
|||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GoalInput extends StatelessWidget {
|
||||
const GoalInput(
|
||||
{super.key,
|
||||
required this.currentAverage,
|
||||
required this.value,
|
||||
required this.onChanged});
|
||||
|
||||
final double currentAverage;
|
||||
final double value;
|
||||
final void Function(double value) onChanged;
|
||||
|
||||
void offsetToValue(Offset offset, Size size) {
|
||||
double v = ((offset.dx / size.width * 4 + 1) * 10).round() / 10;
|
||||
v = v.clamp(1.5, 5);
|
||||
v = v.clamp(((currentAverage * 10).round() / 10), 5);
|
||||
setValue(v);
|
||||
}
|
||||
|
||||
void setValue(double v) {
|
||||
if (v != value) {
|
||||
HapticFeedback.lightImpact();
|
||||
}
|
||||
onChanged(v);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SettingsProvider settings = Provider.of<SettingsProvider>(context);
|
||||
|
||||
List<int> presets = [2, 3, 4, 5];
|
||||
presets = presets.where((e) => gradeToAvg(e) > currentAverage).toList();
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
LayoutBuilder(builder: (context, size) {
|
||||
return GestureDetector(
|
||||
onTapDown: (details) {
|
||||
offsetToValue(details.localPosition, size.biggest);
|
||||
},
|
||||
onHorizontalDragUpdate: (details) {
|
||||
offsetToValue(details.localPosition, size.biggest);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 32.0,
|
||||
width: double.infinity,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 20.0),
|
||||
child: CustomPaint(
|
||||
painter: GoalSliderPainter(
|
||||
value: (value - 1) / 4,
|
||||
settings: settings,
|
||||
goalValue: value),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
// const SizedBox(height: 12.0),
|
||||
// Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: presets.map((e) {
|
||||
// final pv = (value * 10).round() / 10;
|
||||
// final selected = gradeToAvg(e) == pv;
|
||||
// return Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
// child: Container(
|
||||
// decoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(99.0),
|
||||
// color:
|
||||
// gradeColor(e, settings).withOpacity(selected ? 1.0 : 0.2),
|
||||
// border: Border.all(color: gradeColor(e, settings), width: 4),
|
||||
// ),
|
||||
// child: Material(
|
||||
// type: MaterialType.transparency,
|
||||
// child: InkWell(
|
||||
// borderRadius: BorderRadius.circular(99.0),
|
||||
// onTap: () => setValue(gradeToAvg(e)),
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.symmetric(
|
||||
// vertical: 2.0, horizontal: 24.0),
|
||||
// child: Text(
|
||||
// e.toString(),
|
||||
// style: TextStyle(
|
||||
// color:
|
||||
// selected ? Colors.white : gradeColor(e, settings),
|
||||
// fontWeight: FontWeight.bold,
|
||||
// fontSize: 24.0,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }).toList(),
|
||||
// )
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GoalSliderPainter extends CustomPainter {
|
||||
final double value;
|
||||
final SettingsProvider settings;
|
||||
final double goalValue;
|
||||
|
||||
GoalSliderPainter(
|
||||
{required this.value, required this.settings, required this.goalValue});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final radius = size.height / 2;
|
||||
const cpadding = 4;
|
||||
final rect = Rect.fromLTWH(0, 0, size.width + radius, size.height);
|
||||
// final vrect = Rect.fromLTWH(0, 0, size.width * value + radius, size.height);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
rect,
|
||||
const Radius.circular(99.0),
|
||||
),
|
||||
Paint()..color = Colors.black.withOpacity(.1),
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
rect,
|
||||
const Radius.circular(99.0),
|
||||
),
|
||||
Paint()
|
||||
..shader = LinearGradient(colors: [
|
||||
settings.gradeColors[0],
|
||||
settings.gradeColors[1],
|
||||
settings.gradeColors[2],
|
||||
settings.gradeColors[3],
|
||||
settings.gradeColors[4],
|
||||
]).createShader(rect),
|
||||
);
|
||||
|
||||
double w = size.width + radius;
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(
|
||||
(w - (w * 0.986)) / 2,
|
||||
(size.height - (size.height * 0.85)) / 2,
|
||||
w * 0.986,
|
||||
size.height * 0.85),
|
||||
const Radius.circular(99.0),
|
||||
),
|
||||
Paint()..color = Colors.white.withOpacity(.8),
|
||||
);
|
||||
|
||||
canvas.drawOval(
|
||||
Rect.fromCircle(
|
||||
center: Offset(size.width * value, size.height / 2),
|
||||
radius: radius - cpadding),
|
||||
Paint()..color = Colors.white,
|
||||
);
|
||||
canvas.drawOval(
|
||||
Rect.fromCircle(
|
||||
center: Offset(size.width * value, size.height / 2),
|
||||
radius: (radius - cpadding) * 0.8),
|
||||
Paint()..color = gradeColor(goalValue.round(), settings),
|
||||
);
|
||||
|
||||
for (int i = 1; i < 4; i++) {
|
||||
canvas.drawOval(
|
||||
Rect.fromCircle(
|
||||
center: Offset(size.width / 4 * i, size.height / 2), radius: 4),
|
||||
Paint()..color = Colors.white.withOpacity(.6),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(GoalSliderPainter oldDelegate) {
|
||||
return oldDelegate.value != value;
|
||||
}
|
||||
}
|
||||
|
||||
double gradeToAvg(int grade) {
|
||||
return grade - 0.5;
|
||||
}
|
||||
|
||||
Color gradeColor(int grade, SettingsProvider settings) {
|
||||
// return [
|
||||
// const Color(0xffFF3B30),
|
||||
// const Color(0xffFF9F0A),
|
||||
// const Color(0xffFFD60A),
|
||||
// const Color(0xff34C759),
|
||||
// const Color(0xff247665),
|
||||
// ].elementAt(grade.clamp(1, 5) - 1);
|
||||
return [
|
||||
settings.gradeColors[0],
|
||||
settings.gradeColors[1],
|
||||
settings.gradeColors[2],
|
||||
settings.gradeColors[3],
|
||||
settings.gradeColors[4],
|
||||
].elementAt(grade.clamp(1, 5) - 1);
|
||||
}
|
191
lib/ui/mobile/goal_planner/goal_planner.dart
Normal file
191
lib/ui/mobile/goal_planner/goal_planner.dart
Normal file
|
@ -0,0 +1,191 @@
|
|||
/*
|
||||
* Maintainer: DarK
|
||||
* Translated from C version
|
||||
* Minimal Working Fixed @ 2022.12.25
|
||||
* ##Please do NOT modify if you don't know whats going on##
|
||||
*
|
||||
* Issue: #59
|
||||
*
|
||||
* Future changes / ideas:
|
||||
* - `best` should be configurable
|
||||
*/
|
||||
import 'dart:math';
|
||||
import 'package:refilc_kreta_api/models/category.dart';
|
||||
import 'package:refilc_kreta_api/models/grade.dart';
|
||||
import 'package:refilc_kreta_api/models/subject.dart';
|
||||
import 'package:refilc_kreta_api/models/teacher.dart';
|
||||
import 'package:flutter/foundation.dart' show listEquals;
|
||||
|
||||
/// Generate list of grades that achieve the wanted goal.
|
||||
/// After generating possible options, it (when doing so would NOT result in empty list) filters with two criteria:
|
||||
/// - Plan should not contain more than 15 grades
|
||||
/// - Plan should not contain only one type of grade
|
||||
///
|
||||
/// **Usage**:
|
||||
///
|
||||
/// ```dart
|
||||
/// List<int> GoalPlanner(double goal, List<Grade> grades).solve().plan
|
||||
/// ```
|
||||
class GoalPlanner {
|
||||
final double goal;
|
||||
final List<Grade> grades;
|
||||
List<Plan> plans = [];
|
||||
GoalPlanner(this.goal, this.grades);
|
||||
|
||||
bool _allowed(int grade) => grade > goal;
|
||||
|
||||
void _generate(Generator g) {
|
||||
// Exit condition 1: Generator has working plan.
|
||||
if (g.currentAvg.avg >= goal) {
|
||||
plans.add(Plan(g.plan));
|
||||
return;
|
||||
}
|
||||
// Exit condition 2: Generator plan will never work.
|
||||
if (!_allowed(g.gradeToAdd)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = g.max; i >= 0; i--) {
|
||||
int newGradeToAdd = g.gradeToAdd - 1;
|
||||
List<int> newPlan =
|
||||
GoalPlannerHelper._addToList<int>(g.plan, g.gradeToAdd, i);
|
||||
|
||||
Avg newAvg = GoalPlannerHelper._addToAvg(g.currentAvg, g.gradeToAdd, i);
|
||||
int newN = GoalPlannerHelper.howManyNeeded(
|
||||
newGradeToAdd,
|
||||
grades +
|
||||
newPlan
|
||||
.map((e) => Grade(
|
||||
id: '',
|
||||
date: DateTime(0),
|
||||
value: GradeValue(e, '', '', 100),
|
||||
teacher: Teacher.fromString(''),
|
||||
description: '',
|
||||
form: '',
|
||||
groupId: '',
|
||||
type: GradeType.midYear,
|
||||
subject: GradeSubject.fromJson({}),
|
||||
mode: Category.fromJson({}),
|
||||
seenDate: DateTime(0),
|
||||
writeDate: DateTime(0),
|
||||
))
|
||||
.toList(),
|
||||
goal);
|
||||
|
||||
_generate(Generator(newGradeToAdd, newN, newAvg, newPlan));
|
||||
}
|
||||
}
|
||||
|
||||
List<Plan> solve() {
|
||||
_generate(
|
||||
Generator(
|
||||
5,
|
||||
GoalPlannerHelper.howManyNeeded(
|
||||
5,
|
||||
grades,
|
||||
goal,
|
||||
),
|
||||
Avg(GoalPlannerHelper.averageEvals(grades),
|
||||
GoalPlannerHelper.weightSum(grades)),
|
||||
[],
|
||||
),
|
||||
);
|
||||
|
||||
// Calculate Statistics
|
||||
for (var e in plans) {
|
||||
e.sum = e.plan.fold(0, (int a, b) => a + b);
|
||||
e.avg = e.sum / e.plan.length;
|
||||
e.sigma = sqrt(
|
||||
e.plan.map((i) => pow(i - e.avg, 2)).fold(0, (num a, b) => a + b) /
|
||||
e.plan.length);
|
||||
}
|
||||
|
||||
// filter without aggression
|
||||
if (plans.where((e) => e.plan.length < 30).isNotEmpty) {
|
||||
plans.removeWhere((e) => !(e.plan.length < 30));
|
||||
}
|
||||
if (plans.where((e) => e.sigma > 1).isNotEmpty) {
|
||||
plans.removeWhere((e) => !(e.sigma > 1));
|
||||
}
|
||||
|
||||
return plans;
|
||||
}
|
||||
}
|
||||
|
||||
class Avg {
|
||||
final double avg;
|
||||
final double n;
|
||||
|
||||
Avg(this.avg, this.n);
|
||||
}
|
||||
|
||||
class Generator {
|
||||
final int gradeToAdd;
|
||||
final int max;
|
||||
final Avg currentAvg;
|
||||
final List<int> plan;
|
||||
|
||||
Generator(this.gradeToAdd, this.max, this.currentAvg, this.plan);
|
||||
}
|
||||
|
||||
class Plan {
|
||||
final List<int> plan;
|
||||
int sum = 0;
|
||||
double avg = 0;
|
||||
int med = 0; // currently
|
||||
int mod = 0; // unused
|
||||
double sigma = 0;
|
||||
|
||||
Plan(this.plan);
|
||||
|
||||
String get dbString {
|
||||
var finalString = '';
|
||||
for (var i in plan) {
|
||||
finalString += "$i,";
|
||||
}
|
||||
return finalString;
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(other) => other is Plan && listEquals(plan, other.plan);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hashAll(plan);
|
||||
}
|
||||
|
||||
class GoalPlannerHelper {
|
||||
static Avg _addToAvg(Avg base, int grade, int n) =>
|
||||
Avg((base.avg * base.n + grade * n) / (base.n + n), base.n + n);
|
||||
|
||||
static List<T> _addToList<T>(List<T> l, T e, int n) {
|
||||
if (n == 0) return l;
|
||||
List<T> tmp = l;
|
||||
for (int i = 0; i < n; i++) {
|
||||
tmp = tmp + [e];
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static int howManyNeeded(int grade, List<Grade> base, double goal) {
|
||||
double avg = averageEvals(base);
|
||||
double wsum = weightSum(base);
|
||||
if (avg >= goal) return 0;
|
||||
if (grade * 1.0 == goal) return -1;
|
||||
int candidate = (wsum * (avg - goal) / (goal - grade)).floor();
|
||||
return (candidate * grade + avg * wsum) / (candidate + wsum) < goal
|
||||
? candidate + 1
|
||||
: candidate;
|
||||
}
|
||||
|
||||
static double averageEvals(List<Grade> grades, {bool finalAvg = false}) {
|
||||
double average = grades
|
||||
.map((e) => e.value.value * e.value.weight / 100.0)
|
||||
.fold(0.0, (double a, double b) => a + b) /
|
||||
weightSum(grades, finalAvg: finalAvg);
|
||||
return average.isNaN ? 0.0 : average;
|
||||
}
|
||||
|
||||
static double weightSum(List<Grade> grades, {bool finalAvg = false}) => grades
|
||||
.map((e) => finalAvg ? 1 : e.value.weight / 100)
|
||||
.fold(0, (a, b) => a + b);
|
||||
}
|
453
lib/ui/mobile/goal_planner/goal_planner_screen.dart
Normal file
453
lib/ui/mobile/goal_planner/goal_planner_screen.dart
Normal file
|
@ -0,0 +1,453 @@
|
|||
import 'package:refilc/api/providers/database_provider.dart';
|
||||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/helpers/average_helper.dart';
|
||||
import 'package:refilc/helpers/subject.dart';
|
||||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc_kreta_api/models/grade.dart';
|
||||
import 'package:refilc_kreta_api/models/group_average.dart';
|
||||
import 'package:refilc_kreta_api/models/subject.dart';
|
||||
import 'package:refilc_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/average_display.dart';
|
||||
import 'package:refilc_mobile_ui/common/round_border_icon.dart';
|
||||
import 'package:refilc_mobile_ui/pages/grades/calculator/grade_calculator_provider.dart';
|
||||
import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_input.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_planner.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_planner_screen.i18n.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_track_popup.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/route_option.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
enum PlanResult {
|
||||
available, // There are possible solutions
|
||||
unreachable, // The solutions are too hard don't even try
|
||||
unsolvable, // There are no solutions
|
||||
reached, // Goal already reached
|
||||
}
|
||||
|
||||
class GoalPlannerScreen extends StatefulWidget {
|
||||
final GradeSubject subject;
|
||||
|
||||
const GoalPlannerScreen({super.key, required this.subject});
|
||||
|
||||
@override
|
||||
State<GoalPlannerScreen> createState() => _GoalPlannerScreenState();
|
||||
}
|
||||
|
||||
class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
|
||||
late GradeProvider gradeProvider;
|
||||
late GradeCalculatorProvider calculatorProvider;
|
||||
late SettingsProvider settingsProvider;
|
||||
late DatabaseProvider dbProvider;
|
||||
late UserProvider user;
|
||||
|
||||
bool gradeCalcMode = false;
|
||||
|
||||
List<Grade> getSubjectGrades(GradeSubject subject) => !gradeCalcMode
|
||||
? gradeProvider.grades.where((e) => e.subject == subject).toList()
|
||||
: calculatorProvider.grades.where((e) => e.subject == subject).toList();
|
||||
|
||||
double goalValue = 4.0;
|
||||
List<Grade> grades = [];
|
||||
|
||||
Plan? recommended;
|
||||
Plan? fastest;
|
||||
Plan? selectedRoute;
|
||||
List<Plan> otherPlans = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
user = Provider.of<UserProvider>(context, listen: false);
|
||||
dbProvider = Provider.of<DatabaseProvider>(context, listen: false);
|
||||
}
|
||||
|
||||
Future<Map<String, String>> fetchGoalPlans() async {
|
||||
return await dbProvider.userQuery.subjectGoalPlans(userId: user.id!);
|
||||
}
|
||||
|
||||
Future<Map<String, String>> fetchGoalAverages() async {
|
||||
return await dbProvider.userQuery.subjectGoalAverages(userId: user.id!);
|
||||
}
|
||||
|
||||
// haha bees lol
|
||||
Future<Map<String, String>> fetchGoalBees() async {
|
||||
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);
|
||||
|
||||
recommended = null;
|
||||
fastest = null;
|
||||
otherPlans = [];
|
||||
|
||||
if (currentAvg >= goalValue) return PlanResult.reached;
|
||||
|
||||
final planner = GoalPlanner(goalValue, grades);
|
||||
final plans = planner.solve();
|
||||
|
||||
plans.sort((a, b) => (a.avg - (2 * goalValue + 5) / 3)
|
||||
.abs()
|
||||
.compareTo(b.avg - (2 * goalValue + 5) / 3));
|
||||
|
||||
try {
|
||||
final singleSolution = plans.every((e) => e.sigma == 0);
|
||||
recommended =
|
||||
plans.where((e) => singleSolution ? true : e.sigma > 0).first;
|
||||
plans.removeWhere((e) => e == recommended);
|
||||
} catch (_) {}
|
||||
|
||||
plans.sort((a, b) => a.plan.length.compareTo(b.plan.length));
|
||||
|
||||
try {
|
||||
fastest = plans.removeAt(0);
|
||||
} catch (_) {}
|
||||
|
||||
// print((recommended?.plan.length ?? 0).toString() + '-kuki');
|
||||
// print((fastest?.plan.length ?? 0).toString() + '--asd');
|
||||
|
||||
if ((((recommended?.plan.length ?? 0) - (fastest?.plan.length ?? 0)) >=
|
||||
5) &&
|
||||
fastest != null) {
|
||||
recommended = fastest;
|
||||
}
|
||||
|
||||
if (recommended == null) {
|
||||
recommended = null;
|
||||
fastest = null;
|
||||
otherPlans = [];
|
||||
selectedRoute = null;
|
||||
return PlanResult.unsolvable;
|
||||
}
|
||||
|
||||
// print(recommended!.plan.length.toString() + '--------');
|
||||
|
||||
if (recommended!.plan.length > 20) {
|
||||
recommended = null;
|
||||
fastest = null;
|
||||
otherPlans = [];
|
||||
selectedRoute = null;
|
||||
return PlanResult.unreachable;
|
||||
}
|
||||
|
||||
otherPlans = List.from(plans);
|
||||
|
||||
// only save 2 items if not plus member
|
||||
if (!Provider.of<PlusProvider>(context)
|
||||
.hasScope(PremiumScopes.unlimitedGoalPlanner)) {
|
||||
if (otherPlans.length > 2) {
|
||||
otherPlans.removeRange(2, otherPlans.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return PlanResult.available;
|
||||
}
|
||||
|
||||
void getGrades() {
|
||||
grades = getSubjectGrades(widget.subject).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
gradeProvider = Provider.of<GradeProvider>(context);
|
||||
calculatorProvider = Provider.of<GradeCalculatorProvider>(context);
|
||||
settingsProvider = Provider.of<SettingsProvider>(context);
|
||||
|
||||
getGrades();
|
||||
|
||||
final currentAvg = GoalPlannerHelper.averageEvals(grades);
|
||||
|
||||
final result = getResult();
|
||||
|
||||
List<Grade> subjectGrades = getSubjectGrades(widget.subject);
|
||||
|
||||
double avg = AverageHelper.averageEvals(subjectGrades);
|
||||
|
||||
var nullavg = GroupAverage(average: 0.0, subject: widget.subject, uid: "0");
|
||||
double groupAverage = gradeProvider.groupAverages
|
||||
.firstWhere((e) => e.subject == widget.subject, orElse: () => nullavg)
|
||||
.average;
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 5.0,
|
||||
bottom: 220.0,
|
||||
right: 15.0,
|
||||
left: 2.0,
|
||||
),
|
||||
children: [
|
||||
// Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// children: [
|
||||
// const BackButton(),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(right: 15.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Text(
|
||||
// 'goal_planner_title'.i18n,
|
||||
// style: const TextStyle(
|
||||
// fontWeight: FontWeight.w500, fontSize: 18.0),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// width: 5,
|
||||
// ),
|
||||
// const BetaChip(),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const BackButton(),
|
||||
BackButton(
|
||||
color: Colors.red,
|
||||
onPressed: () =>
|
||||
GoalTrackPopup.show(context, subject: widget.subject),
|
||||
),
|
||||
RoundBorderIcon(
|
||||
icon: Icon(
|
||||
SubjectIcon.resolveVariant(
|
||||
context: context,
|
||||
subject: widget.subject,
|
||||
),
|
||||
size: 18,
|
||||
weight: 1.5,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 5.0,
|
||||
),
|
||||
Text(
|
||||
(widget.subject.isRenamed
|
||||
? widget.subject.renamedTo
|
||||
: widget.subject.name) ??
|
||||
'goal_planner_title'.i18n,
|
||||
style: const TextStyle(
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
if (groupAverage != 0)
|
||||
AverageDisplay(average: groupAverage, border: true),
|
||||
const SizedBox(width: 6.0),
|
||||
AverageDisplay(average: avg),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 22.0, right: 22.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"set_a_goal".i18n,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4.0),
|
||||
Text(
|
||||
goalValue.toString(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 48.0,
|
||||
color: gradeColor(goalValue.round(), settingsProvider),
|
||||
),
|
||||
),
|
||||
// Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// Text(
|
||||
// "select_subject".i18n,
|
||||
// style: const TextStyle(
|
||||
// fontWeight: FontWeight.bold,
|
||||
// fontSize: 20.0,
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 4.0),
|
||||
// Column(
|
||||
// children: [
|
||||
// Icon(
|
||||
// SubjectIcon.resolveVariant(
|
||||
// context: context,
|
||||
// subject: widget.subject,
|
||||
// ),
|
||||
// size: 48.0,
|
||||
// ),
|
||||
// Text(
|
||||
// (widget.subject.isRenamed
|
||||
// ? widget.subject.renamedTo
|
||||
// : widget.subject.name) ??
|
||||
// '',
|
||||
// style: const TextStyle(
|
||||
// fontSize: 17.0,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// ),
|
||||
// )
|
||||
// ],
|
||||
// )
|
||||
// ],
|
||||
// )
|
||||
const SizedBox(height: 24.0),
|
||||
Text(
|
||||
"pick_route".i18n,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12.0),
|
||||
if (recommended != null)
|
||||
RouteOption(
|
||||
plan: recommended!,
|
||||
mark: RouteMark.recommended,
|
||||
selected: selectedRoute == recommended!,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = recommended;
|
||||
}),
|
||||
),
|
||||
if (fastest != null && fastest != recommended)
|
||||
RouteOption(
|
||||
plan: fastest!,
|
||||
mark: RouteMark.fastest,
|
||||
selected: selectedRoute == fastest!,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = fastest;
|
||||
}),
|
||||
),
|
||||
...otherPlans.map((e) => RouteOption(
|
||||
plan: e,
|
||||
selected: selectedRoute == e,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = e;
|
||||
}),
|
||||
)),
|
||||
if (result != PlanResult.available) Text(result.name.i18n),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
bottomSheet: MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeBottom: false,
|
||||
removeTop: true,
|
||||
child: Container(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(top: 24.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius:
|
||||
const BorderRadius.vertical(top: Radius.circular(24.0)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(.1),
|
||||
blurRadius: 8.0,
|
||||
)
|
||||
]),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
GoalInput(
|
||||
value: goalValue,
|
||||
currentAverage: currentAvg,
|
||||
onChanged: (v) => setState(() {
|
||||
selectedRoute = null;
|
||||
goalValue = v;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 24.0),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: RawMaterialButton(
|
||||
onPressed: () async {
|
||||
if (selectedRoute == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text('${"pick_route".i18n}...')));
|
||||
}
|
||||
|
||||
final goalPlans = await fetchGoalPlans();
|
||||
final goalAvgs = await fetchGoalAverages();
|
||||
final goalBeforeGrades = await fetchGoalBees();
|
||||
final goalPinDates = await fetchGoalPinDates();
|
||||
|
||||
goalPlans[widget.subject.id] =
|
||||
selectedRoute!.dbString;
|
||||
goalAvgs[widget.subject.id] =
|
||||
goalValue.toStringAsFixed(2);
|
||||
goalBeforeGrades[widget.subject.id] =
|
||||
avg.toStringAsFixed(2);
|
||||
goalPinDates[widget.subject.id] =
|
||||
DateTime.now().toIso8601String();
|
||||
// goalPlans[widget.subject.id] = '1,2,3,4,5,';
|
||||
// goalAvgs[widget.subject.id] = '3.69';
|
||||
// goalBeforeGrades[widget.subject.id] = '3.69';
|
||||
// goalPinDates[widget.subject.id] =
|
||||
// DateTime.now().toIso8601String();
|
||||
|
||||
await dbProvider.userStore.storeSubjectGoalPlans(
|
||||
goalPlans,
|
||||
userId: user.id!);
|
||||
await dbProvider.userStore.storeSubjectGoalAverages(
|
||||
goalAvgs,
|
||||
userId: user.id!);
|
||||
await dbProvider.userStore.storeSubjectGoalBefores(
|
||||
goalBeforeGrades,
|
||||
userId: user.id!);
|
||||
await dbProvider.userStore.storeSubjectGoalPinDates(
|
||||
goalPinDates,
|
||||
userId: user.id!);
|
||||
|
||||
// ignore: use_build_context_synchronously
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
fillColor: Theme.of(context).colorScheme.secondary,
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(
|
||||
"track_it".i18n,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
70
lib/ui/mobile/goal_planner/goal_planner_screen.i18n.dart
Normal file
70
lib/ui/mobile/goal_planner/goal_planner_screen.i18n.dart
Normal file
|
@ -0,0 +1,70 @@
|
|||
import 'package:i18n_extension/i18n_extension.dart';
|
||||
|
||||
extension Localization on String {
|
||||
static final _t = Translations.byLocale("hu_hu") +
|
||||
{
|
||||
"en_en": {
|
||||
"goal_planner_title": "Goal Planning",
|
||||
"set_a_goal": "Your Goal",
|
||||
"select_subject": "Subject",
|
||||
"pick_route": "Pick a Route",
|
||||
"track_it": "Track it!",
|
||||
"recommended": "Recommended",
|
||||
"fastest": "Fastest",
|
||||
"unsolvable": "Unsolvable :(",
|
||||
"unreachable": "Unreachable :(",
|
||||
"reached": "Already reached! :D",
|
||||
// new plan popup
|
||||
"goalplan_title": "Goal Planning",
|
||||
"goalplan_subtitle": "Enter the average you want to achieve!",
|
||||
"goalplan_plans_title": "Choose the route",
|
||||
"goalplan_plans_subtitle":
|
||||
"You can achieve your goal with these tickets, choose one that you like the most! You can change this later.",
|
||||
"show_my_ways": "Show me my options!",
|
||||
},
|
||||
"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",
|
||||
"unsolvable": "Megoldhatatlan :(",
|
||||
"unreachable": "Elérhetetlen :(",
|
||||
"reached": "Már elérted! :D",
|
||||
// new plan popup
|
||||
"goalplan_title": "Cél kitűzése",
|
||||
"goalplan_subtitle": "Add meg az elérni kívánt átlagot!",
|
||||
"goalplan_plans_title": "Válaszd ki az utat",
|
||||
"goalplan_plans_subtitle":
|
||||
"Ezekkel a jegyekkel érheted el a célodat, válassz egyet, ami a legjobban tetszik! Ezt később változtathatod.",
|
||||
"show_my_ways": "Mutasd a lehetőségeimet!",
|
||||
},
|
||||
"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",
|
||||
"unsolvable": "Unlösbar :(",
|
||||
"unreachable": "Unerreichbar :(",
|
||||
"reached": "Bereits erreicht! :D",
|
||||
// new plan popup
|
||||
"goalplan_title": "Zielplanung",
|
||||
"goalplan_subtitle":
|
||||
"Geben Sie den Durchschnitt ein, den Sie erreichen möchten!",
|
||||
"goalplan_plans_title": "Wählen Sie die Route",
|
||||
"goalplan_plans_subtitle":
|
||||
"Sie können Ihr Ziel mit diesen Tickets erreichen. Wählen Sie eines aus, das Ihnen am besten gefällt! Sie können dies später ändern.",
|
||||
"show_my_ways": "Zeigen Sie mir meine Optionen!",
|
||||
},
|
||||
};
|
||||
|
||||
String get i18n => localize(this, _t);
|
||||
String fill(List<Object> params) => localizeFill(this, params);
|
||||
String plural(int value) => localizePlural(value, this, _t);
|
||||
String version(Object modifier) => localizeVersion(modifier, this, _t);
|
||||
}
|
471
lib/ui/mobile/goal_planner/goal_state_screen.dart
Normal file
471
lib/ui/mobile/goal_planner/goal_state_screen.dart
Normal file
|
@ -0,0 +1,471 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:refilc/api/providers/database_provider.dart';
|
||||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/helpers/average_helper.dart';
|
||||
import 'package:refilc/helpers/subject.dart';
|
||||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc_kreta_api/models/grade.dart';
|
||||
import 'package:refilc_kreta_api/models/subject.dart';
|
||||
import 'package:refilc_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/action_button.dart';
|
||||
import 'package:refilc_mobile_ui/common/average_display.dart';
|
||||
import 'package:refilc_mobile_ui/common/panel/panel.dart';
|
||||
import 'package:refilc_mobile_ui/common/progress_bar.dart';
|
||||
import 'package:refilc_mobile_ui/common/round_border_icon.dart';
|
||||
import 'package:refilc_plus/providers/goal_provider.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_planner.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_state_screen.i18n.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_track_popup.dart';
|
||||
import 'package:refilc_plus/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';
|
||||
|
||||
import 'graph.dart';
|
||||
|
||||
class GoalStateScreen extends StatefulWidget {
|
||||
final GradeSubject subject;
|
||||
|
||||
const GoalStateScreen({super.key, required this.subject});
|
||||
|
||||
@override
|
||||
State<GoalStateScreen> createState() => _GoalStateScreenState();
|
||||
}
|
||||
|
||||
class _GoalStateScreenState extends State<GoalStateScreen> {
|
||||
late UserProvider user;
|
||||
late DatabaseProvider db;
|
||||
late GradeProvider gradeProvider;
|
||||
late SettingsProvider settingsProvider;
|
||||
|
||||
double currAvg = 0.0;
|
||||
double goalAvg = 0.0;
|
||||
double beforeAvg = 0.0;
|
||||
double afterAvg = 0.0;
|
||||
double avgDifference = 0;
|
||||
|
||||
Plan? plan;
|
||||
|
||||
late Widget gradeGraph;
|
||||
|
||||
DateTime goalPinDate = DateTime.now();
|
||||
|
||||
void fetchGoalAverages() async {
|
||||
var goalAvgRes = await db.userQuery.subjectGoalAverages(userId: user.id!);
|
||||
var beforeAvgRes = await db.userQuery.subjectGoalBefores(userId: user.id!);
|
||||
|
||||
goalPinDate = DateTime.parse((await db.userQuery
|
||||
.subjectGoalPinDates(userId: user.id!))[widget.subject.id]!);
|
||||
|
||||
String? goalAvgStr = goalAvgRes[widget.subject.id];
|
||||
String? beforeAvgStr = beforeAvgRes[widget.subject.id];
|
||||
goalAvg = double.parse(goalAvgStr ?? '0.0');
|
||||
beforeAvg = double.parse(beforeAvgStr ?? '0.0');
|
||||
|
||||
avgDifference = ((goalAvg - beforeAvg) / beforeAvg.abs()) * 100;
|
||||
|
||||
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(GradeSubject subject) =>
|
||||
gradeProvider.grades.where((e) => (e.subject == subject)).toList();
|
||||
|
||||
List<Grade> getAfterGoalGrades(GradeSubject subject) => gradeProvider.grades
|
||||
.where((e) => (e.subject == subject && e.date.isAfter(goalPinDate)))
|
||||
.toList();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
user = Provider.of<UserProvider>(context, listen: false);
|
||||
db = Provider.of<DatabaseProvider>(context, listen: false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
fetchGoalAverages();
|
||||
fetchGoalPlan();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
gradeProvider = Provider.of<GradeProvider>(context);
|
||||
settingsProvider = Provider.of<SettingsProvider>(context);
|
||||
|
||||
var subjectGrades = getSubjectGrades(widget.subject).toList();
|
||||
currAvg = AverageHelper.averageEvals(subjectGrades);
|
||||
|
||||
var afterGoalGrades = getAfterGoalGrades(widget.subject).toList();
|
||||
afterAvg = AverageHelper.averageEvals(afterGoalGrades);
|
||||
|
||||
Color averageColor = currAvg >= 1 && currAvg <= 5
|
||||
? ColorTween(
|
||||
begin: settingsProvider.gradeColors[currAvg.floor() - 1],
|
||||
end: settingsProvider.gradeColors[currAvg.ceil() - 1])
|
||||
.transform(currAvg - currAvg.floor())!
|
||||
: Theme.of(context).colorScheme.secondary;
|
||||
|
||||
gradeGraph = Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 12.0,
|
||||
bottom: 8.0,
|
||||
),
|
||||
child: Panel(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.only(top: 16.0, right: 12.0),
|
||||
child: GoalGraph(afterGoalGrades,
|
||||
dayThreshold: 5, classAvg: goalAvg),
|
||||
),
|
||||
const SizedBox(height: 5.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'look_at_graph'.i18n,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 23.0,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'thats_progress'.i18n,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15.0),
|
||||
ProgressBar(
|
||||
value: currAvg / goalAvg,
|
||||
backgroundColor: averageColor,
|
||||
height: 16.0,
|
||||
),
|
||||
const SizedBox(height: 8.0),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
body: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
// image: DecorationImage(
|
||||
// image:
|
||||
// AssetImage('assets/images/subject_covers/math_light.png'),
|
||||
// fit: BoxFit.fitWidth,
|
||||
// alignment: Alignment.topCenter,
|
||||
// ),
|
||||
),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Theme.of(context).scaffoldBackgroundColor.withOpacity(0.2),
|
||||
Theme.of(context).scaffoldBackgroundColor,
|
||||
],
|
||||
stops: const [
|
||||
0.1,
|
||||
0.22,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 60.0,
|
||||
left: 2.0,
|
||||
right: 2.0,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const BackButton(),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0)),
|
||||
title: Text("attention".i18n),
|
||||
content: Text("attention_body".i18n),
|
||||
actions: [
|
||||
ActionButton(
|
||||
label: "delete".i18n,
|
||||
onTap: () async {
|
||||
// clear the goal
|
||||
await Provider.of<GoalProvider>(context,
|
||||
listen: false)
|
||||
.clearGoal(widget.subject);
|
||||
// close the modal and the goal page
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(FeatherIcons.trash2),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 22.0),
|
||||
Column(
|
||||
children: [
|
||||
RoundBorderIcon(
|
||||
icon: Icon(
|
||||
SubjectIcon.resolveVariant(
|
||||
context: context,
|
||||
subject: widget.subject,
|
||||
),
|
||||
size: 26.0,
|
||||
weight: 2.5,
|
||||
),
|
||||
padding: 8.0,
|
||||
width: 2.5,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10.0,
|
||||
),
|
||||
Text(
|
||||
(widget.subject.isRenamed
|
||||
? widget.subject.renamedTo
|
||||
: widget.subject.name) ??
|
||||
'goal_planner_title'.i18n,
|
||||
style: const TextStyle(
|
||||
fontSize: 30.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'almost_there'.i18n,
|
||||
style: const TextStyle(
|
||||
fontSize: 22.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 28.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'started_with'.i18n,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5.0),
|
||||
AverageDisplay(average: beforeAvg),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'current'.i18n,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5.0),
|
||||
AverageDisplay(average: currAvg),
|
||||
const SizedBox(width: 5.0),
|
||||
// ide majd kell average difference
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: Panel(
|
||||
padding: const EdgeInsets.all(18.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'your_goal'.i18n,
|
||||
style: const TextStyle(
|
||||
fontSize: 23.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
RawMaterialButton(
|
||||
onPressed: () async {
|
||||
GoalTrackPopup.show(context,
|
||||
subject: widget.subject);
|
||||
// Navigator.of(context).push(
|
||||
// CupertinoPageRoute(
|
||||
// builder: (context) =>
|
||||
// GoalPlannerScreen(
|
||||
// subject: widget.subject)));
|
||||
},
|
||||
fillColor: Colors.black,
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 18.0),
|
||||
child: Text(
|
||||
"change_it".i18n,
|
||||
style: const TextStyle(
|
||||
height: 1.0,
|
||||
color: Colors.white,
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
goalAvg.toString(),
|
||||
style: const TextStyle(
|
||||
height: 1.1,
|
||||
fontSize: 42.0,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10.0),
|
||||
Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 5.0,
|
||||
horizontal: 8.0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(45.0),
|
||||
color: avgDifference.isNegative
|
||||
? Colors.redAccent.shade400
|
||||
.withOpacity(.15)
|
||||
: Colors.greenAccent.shade700
|
||||
.withOpacity(.15),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
avgDifference.isNegative
|
||||
? FeatherIcons.chevronDown
|
||||
: FeatherIcons.chevronUp,
|
||||
color: avgDifference.isNegative
|
||||
? Colors.redAccent.shade400
|
||||
: Colors.greenAccent.shade700,
|
||||
size: 18.0,
|
||||
),
|
||||
const SizedBox(width: 5.0),
|
||||
Text(
|
||||
'${avgDifference.toStringAsFixed(2)}%',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: avgDifference.isNegative
|
||||
? Colors.redAccent.shade400
|
||||
: Colors.greenAccent.shade700,
|
||||
fontSize: 22.0,
|
||||
height: 0.8,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5.0),
|
||||
Padding(
|
||||
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(''),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
87
lib/ui/mobile/goal_planner/goal_state_screen.i18n.dart
Normal file
87
lib/ui/mobile/goal_planner/goal_state_screen.i18n.dart
Normal file
|
@ -0,0 +1,87 @@
|
|||
import 'package:i18n_extension/i18n_extension.dart';
|
||||
|
||||
extension Localization on String {
|
||||
static final _t = Translations.byLocale("hu_hu") +
|
||||
{
|
||||
"en_en": {
|
||||
// base page
|
||||
"goal_planner_title": "Goal Planning",
|
||||
"almost_there": "Almost there! Keep going!",
|
||||
"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:",
|
||||
// done modal
|
||||
"congrats_title": "🎉 Congratulations!",
|
||||
"goal_reached": "You reached your goal after %s days!",
|
||||
"started_at": "You started at",
|
||||
"improved_by": "and improved your grade by %s",
|
||||
"detailed_stats": "See my detailed stats",
|
||||
"later": "Yay! I'll see my stats later.",
|
||||
// sure delete modal
|
||||
"delete": "Delete",
|
||||
"attention": "Attention!",
|
||||
"attention_body":
|
||||
"Your goal and progress will be lost forever and cannot be restored.",
|
||||
},
|
||||
"hu_hu": {
|
||||
// base page
|
||||
"goal_planner_title": "Cél követés",
|
||||
"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:",
|
||||
// done modal
|
||||
"congrats_title": "🎉 Gratulálunk!",
|
||||
"goal_reached": "%s nap után érted el a célod!",
|
||||
"started_at": "Átlagod kezdéskor:",
|
||||
"improved_by": "%s-os javulást értél el!",
|
||||
"detailed_stats": "Részletes statisztikám",
|
||||
"later": "Hurrá! Megnézem máskor.",
|
||||
// sure delete modal
|
||||
"delete": "Törlés",
|
||||
"attention": "Figyelem!",
|
||||
"attention_body":
|
||||
"A kitűzött célod és haladásod örökre elveszik és nem lesz visszaállítható.",
|
||||
},
|
||||
"de_de": {
|
||||
// base page
|
||||
"goal_planner_title": "Zielplanung",
|
||||
"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:",
|
||||
// done modal
|
||||
"congrats_title": "🎉 Glückwunsch!",
|
||||
"goal_reached": "Du hast dein Ziel nach %s Tagen erreicht!",
|
||||
"started_at": "Gesamtbewertung:",
|
||||
"improved_by": "Sie haben %s Verbesserung erreicht!",
|
||||
"detailed_stats": "Detaillierte Statistiken",
|
||||
"later": "Hurra! Ich schaue später nach.",
|
||||
// sure delete modal
|
||||
"delete": "Löschen",
|
||||
"attention": "Achtung!",
|
||||
"attention_body":
|
||||
"Ihr Ziel und Ihr Fortschritt gehen für immer verloren und können nicht wiederhergestellt werden.",
|
||||
},
|
||||
};
|
||||
|
||||
String get i18n => localize(this, _t);
|
||||
String fill(List<Object> params) => localizeFill(this, params);
|
||||
String plural(int value) => localizePlural(value, this, _t);
|
||||
String version(Object modifier) => localizeVersion(modifier, this, _t);
|
||||
}
|
364
lib/ui/mobile/goal_planner/goal_track_popup.dart
Normal file
364
lib/ui/mobile/goal_planner/goal_track_popup.dart
Normal file
|
@ -0,0 +1,364 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:refilc/api/providers/database_provider.dart';
|
||||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/helpers/average_helper.dart';
|
||||
import 'package:refilc_kreta_api/models/grade.dart';
|
||||
import 'package:refilc_kreta_api/models/subject.dart';
|
||||
import 'package:refilc_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/average_display.dart';
|
||||
import 'package:refilc_mobile_ui/common/bottom_sheet_menu/rounded_bottom_sheet.dart';
|
||||
import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_input.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_planner.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_planner_screen.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_planner_screen.i18n.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/route_option.dart';
|
||||
|
||||
class GoalTrackPopup extends StatefulWidget {
|
||||
const GoalTrackPopup({super.key, required this.subject});
|
||||
|
||||
final GradeSubject subject;
|
||||
|
||||
static void show(BuildContext context, {required GradeSubject subject}) =>
|
||||
showRoundedModalBottomSheet(
|
||||
context,
|
||||
child: GoalTrackPopup(subject: subject),
|
||||
showHandle: true,
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
);
|
||||
|
||||
@override
|
||||
GoalTrackPopupState createState() => GoalTrackPopupState();
|
||||
}
|
||||
|
||||
class GoalTrackPopupState extends State<GoalTrackPopup> {
|
||||
late UserProvider user;
|
||||
late DatabaseProvider dbProvider;
|
||||
late GradeProvider gradeProvider;
|
||||
|
||||
List<Grade> getSubjectGrades(GradeSubject subject) =>
|
||||
gradeProvider.grades.where((e) => e.subject == subject).toList();
|
||||
|
||||
double goalValue = 4.0;
|
||||
List<Grade> grades = [];
|
||||
|
||||
Plan? recommended;
|
||||
Plan? fastest;
|
||||
Plan? selectedRoute;
|
||||
List<Plan> otherPlans = [];
|
||||
|
||||
bool plansPage = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
user = Provider.of<UserProvider>(context, listen: false);
|
||||
dbProvider = Provider.of<DatabaseProvider>(context, listen: false);
|
||||
}
|
||||
|
||||
Future<Map<String, String>> fetchGoalPlans() async {
|
||||
return await dbProvider.userQuery.subjectGoalPlans(userId: user.id!);
|
||||
}
|
||||
|
||||
Future<Map<String, String>> fetchGoalAverages() async {
|
||||
return await dbProvider.userQuery.subjectGoalAverages(userId: user.id!);
|
||||
}
|
||||
|
||||
// haha bees lol
|
||||
Future<Map<String, String>> fetchGoalBees() async {
|
||||
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);
|
||||
|
||||
recommended = null;
|
||||
fastest = null;
|
||||
otherPlans = [];
|
||||
|
||||
if (currentAvg >= goalValue) return PlanResult.reached;
|
||||
|
||||
final planner = GoalPlanner(goalValue, grades);
|
||||
final plans = planner.solve();
|
||||
|
||||
plans.sort((a, b) => (a.avg - (2 * goalValue + 5) / 3)
|
||||
.abs()
|
||||
.compareTo(b.avg - (2 * goalValue + 5) / 3));
|
||||
|
||||
try {
|
||||
final singleSolution = plans.every((e) => e.sigma == 0);
|
||||
recommended =
|
||||
plans.where((e) => singleSolution ? true : e.sigma > 0).first;
|
||||
plans.removeWhere((e) => e == recommended);
|
||||
} catch (_) {}
|
||||
|
||||
plans.sort((a, b) => a.plan.length.compareTo(b.plan.length));
|
||||
|
||||
try {
|
||||
fastest = plans.removeAt(0);
|
||||
} catch (_) {}
|
||||
|
||||
// print((recommended?.plan.length ?? 0).toString() + '-kuki');
|
||||
// print((fastest?.plan.length ?? 0).toString() + '--asd');
|
||||
|
||||
if ((((recommended?.plan.length ?? 0) - (fastest?.plan.length ?? 0)) >=
|
||||
5) &&
|
||||
fastest != null) {
|
||||
recommended = fastest;
|
||||
}
|
||||
|
||||
if (recommended == null) {
|
||||
recommended = null;
|
||||
fastest = null;
|
||||
otherPlans = [];
|
||||
selectedRoute = null;
|
||||
return PlanResult.unsolvable;
|
||||
}
|
||||
|
||||
// print(recommended!.plan.length.toString() + '--------');
|
||||
|
||||
if (recommended!.plan.length > 20) {
|
||||
recommended = null;
|
||||
fastest = null;
|
||||
otherPlans = [];
|
||||
selectedRoute = null;
|
||||
return PlanResult.unreachable;
|
||||
}
|
||||
|
||||
otherPlans = List.from(plans);
|
||||
|
||||
// only save 2 items if not plus member
|
||||
if (!Provider.of<PlusProvider>(context)
|
||||
.hasScope(PremiumScopes.unlimitedGoalPlanner)) {
|
||||
if (otherPlans.length > 2) {
|
||||
otherPlans.removeRange(2, otherPlans.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return PlanResult.available;
|
||||
}
|
||||
|
||||
void getGrades() {
|
||||
grades = getSubjectGrades(widget.subject).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
gradeProvider = Provider.of<GradeProvider>(context);
|
||||
|
||||
getGrades();
|
||||
|
||||
final currentAvg = GoalPlannerHelper.averageEvals(grades);
|
||||
|
||||
final result = getResult();
|
||||
|
||||
List<Grade> subjectGrades = getSubjectGrades(widget.subject);
|
||||
|
||||
double avg = AverageHelper.averageEvals(subjectGrades);
|
||||
|
||||
double listLength = (otherPlans.length +
|
||||
(recommended != null ? 1 : 0) +
|
||||
(fastest != null && fastest != recommended ? 1 : 0));
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(top: 24.0),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
AverageDisplay(
|
||||
average: avg,
|
||||
scale: 1.3,
|
||||
),
|
||||
const SizedBox(width: 12.0),
|
||||
const Icon(
|
||||
Icons.arrow_forward,
|
||||
size: 24.0,
|
||||
),
|
||||
const SizedBox(width: 12.0),
|
||||
AverageDisplay(
|
||||
average: goalValue,
|
||||
border: true,
|
||||
dashed: true,
|
||||
scale: 1.3,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 14.0,
|
||||
),
|
||||
Text(
|
||||
plansPage
|
||||
? 'goalplan_plans_title'.i18n
|
||||
: 'goalplan_title'.i18n,
|
||||
style: const TextStyle(
|
||||
fontSize: 20.0, fontWeight: FontWeight.w700),
|
||||
textAlign: TextAlign.center),
|
||||
Text(
|
||||
plansPage
|
||||
? 'goalplan_plans_subtitle'.i18n
|
||||
: 'goalplan_subtitle'.i18n,
|
||||
style: const TextStyle(
|
||||
fontSize: 16.0, fontWeight: FontWeight.w500),
|
||||
textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24.0),
|
||||
if (!plansPage)
|
||||
GoalInput(
|
||||
value: goalValue,
|
||||
currentAverage: currentAvg,
|
||||
onChanged: (v) => setState(() {
|
||||
selectedRoute = null;
|
||||
goalValue = v;
|
||||
}),
|
||||
),
|
||||
if (plansPage && listLength > 2)
|
||||
SizedBox(
|
||||
height: (MediaQuery.of(context).size.height * 0.5),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
if (recommended != null)
|
||||
RouteOption(
|
||||
plan: recommended!,
|
||||
mark: RouteMark.recommended,
|
||||
selected: selectedRoute == recommended!,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = recommended;
|
||||
}),
|
||||
),
|
||||
if (fastest != null && fastest != recommended)
|
||||
RouteOption(
|
||||
plan: fastest!,
|
||||
mark: RouteMark.fastest,
|
||||
selected: selectedRoute == fastest!,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = fastest;
|
||||
}),
|
||||
),
|
||||
...otherPlans.map((e) => RouteOption(
|
||||
plan: e,
|
||||
selected: selectedRoute == e,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = e;
|
||||
}),
|
||||
)),
|
||||
if (result != PlanResult.available)
|
||||
Text(result.name.i18n),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (plansPage && listLength <= 2)
|
||||
Column(
|
||||
children: [
|
||||
if (recommended != null)
|
||||
RouteOption(
|
||||
plan: recommended!,
|
||||
mark: RouteMark.recommended,
|
||||
selected: selectedRoute == recommended!,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = recommended;
|
||||
}),
|
||||
),
|
||||
if (fastest != null && fastest != recommended)
|
||||
RouteOption(
|
||||
plan: fastest!,
|
||||
mark: RouteMark.fastest,
|
||||
selected: selectedRoute == fastest!,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = fastest;
|
||||
}),
|
||||
),
|
||||
...otherPlans.map((e) => RouteOption(
|
||||
plan: e,
|
||||
selected: selectedRoute == e,
|
||||
onSelected: () => setState(() {
|
||||
selectedRoute = e;
|
||||
}),
|
||||
)),
|
||||
if (result != PlanResult.available) Text(result.name.i18n),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24.0),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: RawMaterialButton(
|
||||
onPressed: () async {
|
||||
if (!plansPage) {
|
||||
setState(() {
|
||||
plansPage = true;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedRoute == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('${"pick_route".i18n}...')));
|
||||
}
|
||||
|
||||
final goalPlans = await fetchGoalPlans();
|
||||
final goalAvgs = await fetchGoalAverages();
|
||||
final goalBeforeGrades = await fetchGoalBees();
|
||||
final goalPinDates = await fetchGoalPinDates();
|
||||
|
||||
goalPlans[widget.subject.id] = selectedRoute!.dbString;
|
||||
goalAvgs[widget.subject.id] = goalValue.toStringAsFixed(2);
|
||||
goalBeforeGrades[widget.subject.id] =
|
||||
avg.toStringAsFixed(2);
|
||||
goalPinDates[widget.subject.id] =
|
||||
DateTime.now().toIso8601String();
|
||||
// goalPlans[widget.subject.id] = '1,2,3,4,5,';
|
||||
// goalAvgs[widget.subject.id] = '3.69';
|
||||
// goalBeforeGrades[widget.subject.id] = '3.69';
|
||||
// goalPinDates[widget.subject.id] =
|
||||
// DateTime.now().toIso8601String();
|
||||
|
||||
await dbProvider.userStore
|
||||
.storeSubjectGoalPlans(goalPlans, userId: user.id!);
|
||||
await dbProvider.userStore
|
||||
.storeSubjectGoalAverages(goalAvgs, userId: user.id!);
|
||||
await dbProvider.userStore.storeSubjectGoalBefores(
|
||||
goalBeforeGrades,
|
||||
userId: user.id!);
|
||||
await dbProvider.userStore.storeSubjectGoalPinDates(
|
||||
goalPinDates,
|
||||
userId: user.id!);
|
||||
|
||||
// ignore: use_build_context_synchronously
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
fillColor: Theme.of(context).colorScheme.secondary,
|
||||
shape: const StadiumBorder(),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(
|
||||
plansPage ? "track_it".i18n : "show_my_ways".i18n,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
34
lib/ui/mobile/goal_planner/grade_display.dart
Normal file
34
lib/ui/mobile/goal_planner/grade_display.dart
Normal file
|
@ -0,0 +1,34 @@
|
|||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_input.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GradeDisplay extends StatelessWidget {
|
||||
const GradeDisplay({super.key, required this.grade});
|
||||
|
||||
final int grade;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SettingsProvider settings = Provider.of<SettingsProvider>(context);
|
||||
|
||||
return Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: gradeColor(grade, settings).withOpacity(.3),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
grade.toInt().toString(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 22.0,
|
||||
color: gradeColor(grade, settings),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
269
lib/ui/mobile/goal_planner/graph.dart
Normal file
269
lib/ui/mobile/goal_planner/graph.dart
Normal file
|
@ -0,0 +1,269 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:refilc/helpers/average_helper.dart';
|
||||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_kreta_api/models/grade.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/graph.i18n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GoalGraph extends StatefulWidget {
|
||||
const GoalGraph(this.data, {super.key, this.dayThreshold = 7, this.classAvg});
|
||||
|
||||
final List<Grade> data;
|
||||
final int dayThreshold;
|
||||
final double? classAvg;
|
||||
|
||||
@override
|
||||
GoalGraphState createState() => GoalGraphState();
|
||||
}
|
||||
|
||||
class GoalGraphState extends State<GoalGraph> {
|
||||
late SettingsProvider settings;
|
||||
|
||||
List<FlSpot> getSpots(List<Grade> data) {
|
||||
List<FlSpot> subjectData = [];
|
||||
List<List<Grade>> sortedData = [[]];
|
||||
|
||||
// Sort by date descending
|
||||
data.sort((a, b) => -a.writeDate.compareTo(b.writeDate));
|
||||
|
||||
// Sort data to points by treshold
|
||||
for (var element in data) {
|
||||
if (sortedData.last.isNotEmpty &&
|
||||
sortedData.last.last.writeDate.difference(element.writeDate).inDays >
|
||||
widget.dayThreshold) {
|
||||
sortedData.add([]);
|
||||
}
|
||||
for (var dataList in sortedData) {
|
||||
dataList.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
// Create FlSpots from points
|
||||
for (var dataList in sortedData) {
|
||||
double average = AverageHelper.averageEvals(dataList);
|
||||
|
||||
if (dataList.isNotEmpty) {
|
||||
subjectData.add(FlSpot(
|
||||
dataList[0].writeDate.month +
|
||||
(dataList[0].writeDate.day / 31) +
|
||||
((dataList[0].writeDate.year - data.last.writeDate.year) * 12),
|
||||
double.parse(average.toStringAsFixed(2)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return subjectData;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
settings = Provider.of<SettingsProvider>(context);
|
||||
|
||||
List<FlSpot> subjectSpots = [];
|
||||
List<FlSpot> ghostSpots = [];
|
||||
List<VerticalLine> extraLinesV = [];
|
||||
List<HorizontalLine> extraLinesH = [];
|
||||
|
||||
// Filter data
|
||||
List<Grade> data = widget.data
|
||||
.where((e) => e.value.weight != 0)
|
||||
.where((e) => e.type == GradeType.midYear)
|
||||
.where((e) => e.gradeType?.name == "Osztalyzat")
|
||||
.toList();
|
||||
|
||||
// Filter ghost data
|
||||
List<Grade> ghostData = widget.data
|
||||
.where((e) => e.value.weight != 0)
|
||||
.where((e) => e.type == GradeType.ghost)
|
||||
.toList();
|
||||
|
||||
// Calculate average
|
||||
double average = AverageHelper.averageEvals(data);
|
||||
|
||||
// Calculate graph color
|
||||
Color averageColor = average >= 1 && average <= 5
|
||||
? ColorTween(
|
||||
begin: settings.gradeColors[average.floor() - 1],
|
||||
end: settings.gradeColors[average.ceil() - 1])
|
||||
.transform(average - average.floor())!
|
||||
: Theme.of(context).colorScheme.secondary;
|
||||
|
||||
subjectSpots = getSpots(data);
|
||||
|
||||
// naplo/#73
|
||||
if (subjectSpots.isNotEmpty) {
|
||||
ghostSpots = getSpots(data + ghostData);
|
||||
|
||||
// hax
|
||||
ghostSpots = ghostSpots
|
||||
.where((e) => e.x >= subjectSpots.map((f) => f.x).reduce(max))
|
||||
.toList();
|
||||
ghostSpots = ghostSpots.map((e) => FlSpot(e.x + 0.1, e.y)).toList();
|
||||
ghostSpots.add(subjectSpots.firstWhere(
|
||||
(e) => e.x >= subjectSpots.map((f) => f.x).reduce(max),
|
||||
orElse: () => const FlSpot(-1, -1)));
|
||||
ghostSpots.removeWhere(
|
||||
(element) => element.x == -1 && element.y == -1); // naplo/#74
|
||||
}
|
||||
|
||||
// Horizontal line displaying the class average
|
||||
if (widget.classAvg != null &&
|
||||
widget.classAvg! > 0.0 &&
|
||||
settings.graphClassAvg) {
|
||||
extraLinesH.add(HorizontalLine(
|
||||
y: widget.classAvg!,
|
||||
color: AppColors.of(context).text.withOpacity(.75),
|
||||
));
|
||||
}
|
||||
|
||||
// LineChart is really cute because it tries to render it's contents outside of it's rect.
|
||||
return widget.data.length <= 2
|
||||
? SizedBox(
|
||||
height: 150,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"not_enough_grades".i18n,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
)
|
||||
: ClipRect(
|
||||
child: SizedBox(
|
||||
height: 158,
|
||||
child: subjectSpots.length > 1
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0, right: 8.0),
|
||||
child: LineChart(
|
||||
LineChartData(
|
||||
extraLinesData: ExtraLinesData(
|
||||
verticalLines: extraLinesV,
|
||||
horizontalLines: extraLinesH),
|
||||
lineBarsData: [
|
||||
LineChartBarData(
|
||||
preventCurveOverShooting: true,
|
||||
spots: subjectSpots,
|
||||
isCurved: true,
|
||||
color: averageColor,
|
||||
barWidth: 8,
|
||||
isStrokeCapRound: true,
|
||||
dotData: const FlDotData(show: false),
|
||||
belowBarData: BarAreaData(
|
||||
show: true,
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
averageColor.withOpacity(0.7),
|
||||
averageColor.withOpacity(0.3),
|
||||
averageColor.withOpacity(0.2),
|
||||
averageColor.withOpacity(0.1),
|
||||
],
|
||||
stops: const [0.1, 0.6, 0.8, 1],
|
||||
),
|
||||
// colors: [
|
||||
// averageColor.withOpacity(0.7),
|
||||
// averageColor.withOpacity(0.3),
|
||||
// averageColor.withOpacity(0.2),
|
||||
// averageColor.withOpacity(0.1),
|
||||
// ],
|
||||
// gradientColorStops: [0.1, 0.6, 0.8, 1],
|
||||
// gradientFrom: const Offset(0, 0),
|
||||
// gradientTo: const Offset(0, 1),
|
||||
),
|
||||
),
|
||||
if (ghostData.isNotEmpty && ghostSpots.isNotEmpty)
|
||||
LineChartBarData(
|
||||
preventCurveOverShooting: true,
|
||||
spots: ghostSpots,
|
||||
isCurved: true,
|
||||
color: AppColors.of(context).text,
|
||||
barWidth: 8,
|
||||
isStrokeCapRound: true,
|
||||
dotData: const FlDotData(show: false),
|
||||
belowBarData: BarAreaData(
|
||||
show: true,
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(0.7),
|
||||
AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(0.3),
|
||||
AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(0.2),
|
||||
AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(0.1),
|
||||
],
|
||||
stops: const [0.1, 0.6, 0.8, 1],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
minY: 1,
|
||||
maxY: 5,
|
||||
gridData: const FlGridData(
|
||||
show: true,
|
||||
horizontalInterval: 1,
|
||||
// checkToShowVerticalLine: (_) => false,
|
||||
// getDrawingHorizontalLine: (_) => FlLine(
|
||||
// color: AppColors.of(context).text.withOpacity(.15),
|
||||
// strokeWidth: 2,
|
||||
// ),
|
||||
// getDrawingVerticalLine: (_) => FlLine(
|
||||
// color: AppColors.of(context).text.withOpacity(.25),
|
||||
// strokeWidth: 2,
|
||||
// ),
|
||||
),
|
||||
lineTouchData: LineTouchData(
|
||||
touchTooltipData: const LineTouchTooltipData(
|
||||
// tooltipBgColor: Colors.grey.shade800,
|
||||
fitInsideVertically: true,
|
||||
fitInsideHorizontally: true,
|
||||
),
|
||||
handleBuiltInTouches: true,
|
||||
touchSpotThreshold: 20.0,
|
||||
getTouchedSpotIndicator: (_, spots) {
|
||||
return List.generate(
|
||||
spots.length,
|
||||
(index) => TouchedSpotIndicatorData(
|
||||
FlLine(
|
||||
color: Colors.grey.shade900,
|
||||
strokeWidth: 3.5,
|
||||
),
|
||||
FlDotData(
|
||||
getDotPainter: (a, b, c, d) =>
|
||||
FlDotCirclePainter(
|
||||
strokeWidth: 0,
|
||||
color: Colors.grey.shade900,
|
||||
radius: 10.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
borderData: FlBorderData(
|
||||
show: false,
|
||||
border: Border.all(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
21
lib/ui/mobile/goal_planner/graph.i18n.dart
Normal file
21
lib/ui/mobile/goal_planner/graph.i18n.dart
Normal file
|
@ -0,0 +1,21 @@
|
|||
import 'package:i18n_extension/i18n_extension.dart';
|
||||
|
||||
extension Localization on String {
|
||||
static final _t = Translations.byLocale("hu_hu") +
|
||||
{
|
||||
"en_en": {
|
||||
"not_enough_grades": "Not enough data to show a graph here.",
|
||||
},
|
||||
"hu_hu": {
|
||||
"not_enough_grades": "Nem szereztél még elég jegyet grafikon mutatáshoz.",
|
||||
},
|
||||
"de_de": {
|
||||
"not_enough_grades": "Noch nicht genug Noten, um die Grafik zu zeigen.",
|
||||
},
|
||||
};
|
||||
|
||||
String get i18n => localize(this, _t);
|
||||
String fill(List<Object> params) => localizeFill(this, params);
|
||||
String plural(int value) => localizePlural(value, this, _t);
|
||||
String version(Object modifier) => localizeVersion(modifier, this, _t);
|
||||
}
|
204
lib/ui/mobile/goal_planner/route_option.dart
Normal file
204
lib/ui/mobile/goal_planner/route_option.dart
Normal file
|
@ -0,0 +1,204 @@
|
|||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_planner.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/goal_planner_screen.i18n.dart';
|
||||
import 'package:refilc_plus/ui/mobile/goal_planner/grade_display.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum RouteMark { recommended, fastest }
|
||||
|
||||
class RouteOption extends StatelessWidget {
|
||||
const RouteOption(
|
||||
{super.key,
|
||||
required this.plan,
|
||||
this.mark,
|
||||
this.selected = false,
|
||||
required this.onSelected});
|
||||
|
||||
final Plan plan;
|
||||
final RouteMark? mark;
|
||||
final bool selected;
|
||||
final void Function() onSelected;
|
||||
|
||||
Widget markLabel({Color? colorOverride}) {
|
||||
TextStyle style =
|
||||
TextStyle(fontWeight: FontWeight.bold, color: colorOverride);
|
||||
|
||||
switch (mark!) {
|
||||
case RouteMark.recommended:
|
||||
return Text("recommended".i18n, style: style);
|
||||
case RouteMark.fastest:
|
||||
return Text("fastest".i18n, style: style);
|
||||
}
|
||||
}
|
||||
|
||||
Color markColor(BuildContext context) {
|
||||
switch (mark) {
|
||||
case RouteMark.recommended:
|
||||
return const Color.fromARGB(255, 104, 93, 255);
|
||||
case RouteMark.fastest:
|
||||
return const Color.fromARGB(255, 255, 91, 146);
|
||||
default:
|
||||
return Theme.of(context).colorScheme.primary;
|
||||
}
|
||||
}
|
||||
|
||||
@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 Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12.0),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Card(
|
||||
surfaceTintColor:
|
||||
selected ? markColor(context).withOpacity(.2) : Colors.white,
|
||||
margin: EdgeInsets.zero,
|
||||
elevation: 5,
|
||||
shadowColor: Colors.transparent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
side: selected
|
||||
? BorderSide(color: markColor(context), width: 1.5)
|
||||
: BorderSide.none,
|
||||
),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
onTap: onSelected,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 16.0, bottom: 16.0, left: 20.0, right: 12.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (mark != null) ...[
|
||||
// Chip(
|
||||
// label: markLabel(),
|
||||
// visualDensity: VisualDensity.compact,
|
||||
// backgroundColor:
|
||||
// selected ? markColor(context) : Colors.transparent,
|
||||
// labelPadding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
// labelStyle:
|
||||
// TextStyle(color: selected ? Colors.white : null),
|
||||
// shape: StadiumBorder(
|
||||
// side: BorderSide(
|
||||
// color: markColor(context),
|
||||
// width: 3.0,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
markLabel(
|
||||
colorOverride: selected ? markColor(context) : null),
|
||||
const SizedBox(height: 6.0),
|
||||
],
|
||||
Wrap(
|
||||
spacing: 4.0,
|
||||
runSpacing: 8.0,
|
||||
children: gradeWidgets,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RouteOptionRow extends StatelessWidget {
|
||||
const RouteOptionRow({
|
||||
super.key,
|
||||
required this.plan,
|
||||
this.mark,
|
||||
});
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue