worked on goal planner finish modal

This commit is contained in:
Kima 2023-09-02 14:48:05 +02:00
parent 9078634fb7
commit fef0857050
5 changed files with 312 additions and 94 deletions

View File

@ -0,0 +1,45 @@
import 'package:filcnaplo/api/providers/database_provider.dart';
import 'package:filcnaplo/api/providers/user_provider.dart';
import 'package:filcnaplo_kreta_api/models/subject.dart';
import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
import 'package:flutter/widgets.dart';
class GoalProvider extends ChangeNotifier {
final DatabaseProvider _db;
final UserProvider _user;
final GradeProvider _gradeProvider;
late bool _done = false;
late Subject _doneSubject;
bool get hasDoneGoals => _done;
Subject get doneSubject => _doneSubject;
GoalProvider({
required DatabaseProvider database,
required UserProvider user,
required GradeProvider gradeProvider,
}) : _db = database,
_user = user,
_gradeProvider = gradeProvider;
Future<void> fetchDone() async {
var goalAvgs = await _db.userQuery.subjectGoalAverages(userId: _user.id!);
var beforeAvgs = await _db.userQuery.subjectGoalAverages(userId: _user.id!);
List<Subject> subjects = _gradeProvider.grades
.map((e) => e.subject)
.toSet()
.toList()
..sort((a, b) => a.name.compareTo(b.name));
goalAvgs.forEach((k, v) {
if (beforeAvgs[k] == v) {
_done = true;
_doneSubject = subjects.where((e) => e.id == k).toList()[0];
notifyListeners();
}
});
}
}

View File

@ -1,92 +1,235 @@
// import 'package:filcnaplo/api/providers/database_provider.dart'; import 'package:filcnaplo/api/providers/database_provider.dart';
// import 'package:filcnaplo/api/providers/user_provider.dart'; import 'package:filcnaplo/api/providers/user_provider.dart';
// import 'package:filcnaplo_kreta_api/models/subject.dart'; import 'package:filcnaplo_kreta_api/models/subject.dart';
// import 'package:flutter/material.dart'; import 'package:filcnaplo_mobile_ui/common/average_display.dart';
// import 'package:provider/provider.dart'; import 'package:filcnaplo_premium/ui/mobile/goal_planner/goal_state_screen.i18n.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
// class GoalCompleteModal extends StatelessWidget { class GoalCompleteModal extends StatelessWidget {
// const GoalCompleteModal( const GoalCompleteModal(
// this.subject, { this.subject, {
// Key? key, Key? key,
// required this.user, required this.user,
// required this.database, required this.database,
// required this.goalAverage, required this.goalAverage,
// required this.beforeAverage, required this.beforeAverage,
// required this.averageDifference, required this.averageDifference,
// }) : super(key: key); }) : super(key: key);
// final UserProvider user; final UserProvider user;
// final DatabaseProvider database; final DatabaseProvider database;
// final Subject subject; final Subject subject;
// final double goalAverage; final double goalAverage;
// final double beforeAverage; final double beforeAverage;
// final double averageDifference; final double averageDifference;
// @override @override
// Widget build(BuildContext context) { Widget build(BuildContext context) {
// return Padding( return Dialog(
// padding: const EdgeInsets.symmetric(vertical: 100.0, horizontal: 32.0), elevation: 0,
// child: Material( backgroundColor: Colors.transparent,
// borderRadius: BorderRadius.circular(12.0), child: Container(
// child: Padding( padding: const EdgeInsets.all(16.0),
// padding: const EdgeInsets.all(12.0), decoration: BoxDecoration(
// child: Column( color: Colors.white,
// children: [ borderRadius: BorderRadius.circular(14.0),
// // content or idk ),
// Container( child: Column(
// decoration: const BoxDecoration( crossAxisAlignment: CrossAxisAlignment.center,
// image: DecorationImage( mainAxisAlignment: MainAxisAlignment.center,
// image: AssetImage('assets/images/static_confetti.png'), mainAxisSize: MainAxisSize.min,
// fit: BoxFit.fill, children: [
// alignment: Alignment.topCenter, Container(
// ), width: double.infinity,
// ), decoration: BoxDecoration(
// child: Text( image: const DecorationImage(
// goalAverage.toStringAsFixed(1), image: AssetImage('assets/images/static_confetti.png'),
// style: const TextStyle( fit: BoxFit.fitWidth,
// color: Colors.white, alignment: Alignment.topCenter,
// fontSize: 40.0, ),
// ), color: Colors.white,
// ), borderRadius: BorderRadius.circular(8.0),
// ), ),
// ], padding: const EdgeInsets.all(6.0),
// ), child: Text(
// ), goalAverage.toStringAsFixed(1),
// ), textAlign: TextAlign.center,
// ); style: const TextStyle(
// } color: Colors.white,
fontSize: 64.0,
fontWeight: FontWeight.w800,
),
),
),
const SizedBox(height: 10.0),
Text(
'congrats_title'.i18n,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 27.0,
fontWeight: FontWeight.w700,
height: 1.1,
),
),
Text(
'goal_reached'.i18n.fill(['20']),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.w500,
height: 1.1,
),
),
const SizedBox(height: 18.0),
Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'started_at'.i18n,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.w500,
),
),
const SizedBox(width: 5.0),
AverageDisplay(
average: beforeAverage,
),
],
),
Text(
'improved_by'.i18n.fill([
averageDifference.toStringAsFixed(2) + '%',
]),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.w500,
),
),
],
),
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(8.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(8.0),
color: const Color(0xFFF5FAF9),
),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(
'later'.i18n,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w700,
color: Color(0xFF01342D),
),
),
),
),
),
],
),
],
),
),
);
// static Future<T?> show<T>( // return Padding(
// Subject subject, { // padding: const EdgeInsets.symmetric(vertical: 100.0, horizontal: 32.0),
// required BuildContext context, // child: Material(
// }) async { // borderRadius: BorderRadius.circular(12.0),
// UserProvider user = Provider.of<UserProvider>(context, listen: false); // child: Padding(
// DatabaseProvider db = Provider.of<DatabaseProvider>(context, listen: false); // padding: const EdgeInsets.all(12.0),
// child: Column(
// children: [
// // content or idk
// ],
// ),
// ),
// ),
// );
}
// var goalAvgRes = await db.userQuery.subjectGoalAverages(userId: user.id!); static Future<T?> show<T>(
// var beforeAvgRes = await db.userQuery.subjectGoalBefores(userId: user.id!); Subject subject, {
required BuildContext context,
}) async {
UserProvider user = Provider.of<UserProvider>(context, listen: false);
DatabaseProvider db = Provider.of<DatabaseProvider>(context, listen: false);
// //DateTime goalPinDate = DateTime.parse((await db.userQuery.subjectGoalPinDates(userId: user.id!))[widget.subject.id]!); var goalAvgRes = await db.userQuery.subjectGoalAverages(userId: user.id!);
var beforeAvgRes = await db.userQuery.subjectGoalBefores(userId: user.id!);
// String? goalAvgStr = goalAvgRes[subject.id]; //DateTime goalPinDate = DateTime.parse((await db.userQuery.subjectGoalPinDates(userId: user.id!))[widget.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; String? goalAvgStr = goalAvgRes[subject.id];
String? beforeAvgStr = beforeAvgRes[subject.id];
double goalAvg = double.parse(goalAvgStr ?? '0.0');
double beforeAvg = double.parse(beforeAvgStr ?? '0.0');
// return showDialog<T?>( double avgDifference = ((goalAvg - beforeAvg) / beforeAvg.abs()) * 100;
// context: context,
// builder: (context) => GoalCompleteModal( return showDialog<T?>(
// subject, context: context,
// user: user, builder: (context) => GoalCompleteModal(
// database: db, subject,
// goalAverage: goalAvg, user: user,
// beforeAverage: beforeAvg, database: db,
// averageDifference: avgDifference, goalAverage: goalAvg,
// ), beforeAverage: beforeAvg,
// barrierDismissible: false, averageDifference: avgDifference,
// ); ),
// } barrierDismissible: false,
// } );
}
}

View File

@ -375,12 +375,17 @@ class _GoalPlannerScreenState extends State<GoalPlannerScreen> {
final goalBeforeGrades = await fetchGoalBees(); final goalBeforeGrades = await fetchGoalBees();
final goalPinDates = await fetchGoalPinDates(); final goalPinDates = await fetchGoalPinDates();
goalPlans[widget.subject.id] = // goalPlans[widget.subject.id] =
selectedRoute!.dbString; // selectedRoute!.dbString;
goalAvgs[widget.subject.id] = // goalAvgs[widget.subject.id] =
goalValue.toStringAsFixed(1); // goalValue.toStringAsFixed(2);
goalBeforeGrades[widget.subject.id] = // goalBeforeGrades[widget.subject.id] =
avg.toStringAsFixed(1); // 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] = goalPinDates[widget.subject.id] =
DateTime.now().toIso8601String(); DateTime.now().toIso8601String();

View File

@ -18,6 +18,7 @@ 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';
import 'goal_complete_modal.dart';
import 'goal_planner_screen.dart'; import 'goal_planner_screen.dart';
import 'graph.dart'; import 'graph.dart';
@ -423,12 +424,12 @@ class _GoalStateScreenState extends State<GoalStateScreen> {
plan: plan!, plan: plan!,
) )
: const Text(''), : const Text(''),
// TextButton( TextButton(
// onPressed: () async { onPressed: () async {
// GoalCompleteModal.show(widget.subject, GoalCompleteModal.show(widget.subject,
// context: context); context: context);
// }, },
// child: const Text('faszteszt')) child: const Text('faszteszt'))
], ],
), ),
), ),

View File

@ -4,6 +4,7 @@ extension Localization on String {
static final _t = Translations.byLocale("hu_hu") + static final _t = Translations.byLocale("hu_hu") +
{ {
"en_en": { "en_en": {
// base page
"goal_planner_title": "Goal Planning", "goal_planner_title": "Goal Planning",
"almost_there": "Almost there! Keep going!", "almost_there": "Almost there! Keep going!",
"started_with": "Started with:", "started_with": "Started with:",
@ -14,8 +15,16 @@ extension Localization on String {
"thats_progress": "thats_progress":
"Now that's what I call progress! Push a little more, you're almost there..", "Now that's what I call progress! Push a little more, you're almost there..",
"you_need": "You need:", "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.",
}, },
"hu_hu": { "hu_hu": {
// base page
"goal_planner_title": "Cél követés", "goal_planner_title": "Cél követés",
"almost_there": "Majdnem megvan! Így tovább!", "almost_there": "Majdnem megvan! Így tovább!",
"started_with": "Így kezdődött:", "started_with": "Így kezdődött:",
@ -26,8 +35,16 @@ extension Localization on String {
"thats_progress": "thats_progress":
"Ezt nevezem haladásnak! Hajts még egy kicsit, már majdnem kész..", "Ezt nevezem haladásnak! Hajts még egy kicsit, már majdnem kész..",
"you_need": "Szükséges:", "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.",
}, },
"de_de": { "de_de": {
// base page
"goal_planner_title": "Zielplanung", "goal_planner_title": "Zielplanung",
"almost_there": "Fast dort! Weitermachen!", "almost_there": "Fast dort! Weitermachen!",
"started_with": "Begann mit:", "started_with": "Begann mit:",
@ -38,6 +55,13 @@ extension Localization on String {
"thats_progress": "thats_progress":
"Das nenne ich Fortschritt! Drücken Sie noch ein wenig, Sie haben es fast geschafft..", "Das nenne ich Fortschritt! Drücken Sie noch ein wenig, Sie haben es fast geschafft..",
"you_need": "Du brauchst:", "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.",
}, },
}; };