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,
|
||||
);
|
||||
}
|
||||
}
|
201
lib/ui/mobile/plus/activation_view/activation_dashboard.dart
Normal file
201
lib/ui/mobile/plus/activation_view/activation_dashboard.dart
Normal file
|
@ -0,0 +1,201 @@
|
|||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ActivationDashboard extends StatefulWidget {
|
||||
const ActivationDashboard({super.key});
|
||||
|
||||
@override
|
||||
State<ActivationDashboard> createState() => _ActivationDashboardState();
|
||||
}
|
||||
|
||||
class _ActivationDashboardState extends State<ActivationDashboard> {
|
||||
bool manualActivationLoading = false;
|
||||
|
||||
Future<void> onManualActivation() async {
|
||||
final data = await Clipboard.getData("text/plain");
|
||||
if (data == null || data.text == null || data.text == "") {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
manualActivationLoading = true;
|
||||
});
|
||||
final result =
|
||||
// ignore: use_build_context_synchronously
|
||||
await context.read<PlusProvider>().auth.finishAuth(data.text!);
|
||||
setState(() {
|
||||
manualActivationLoading = false;
|
||||
});
|
||||
|
||||
if (!result && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text(
|
||||
"Sikertelen aktiválás. Kérlek próbáld újra később!",
|
||||
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
|
||||
),
|
||||
backgroundColor: Colors.red,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Image.asset(
|
||||
"assets/icons/ic_rounded.png",
|
||||
height: 64.0,
|
||||
),
|
||||
// child: SvgPicture.asset(
|
||||
// "assets/images/github.svg",
|
||||
// height: 64.0,
|
||||
// ),
|
||||
),
|
||||
const SizedBox(height: 32.0),
|
||||
const Text(
|
||||
"Válassz fizetési módot, majd folytasd a fizetést a Stripe felületén, hogy aktiváld az előfizetésed.",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontWeight: FontWeight.w700, fontSize: 18.0),
|
||||
),
|
||||
// const SizedBox(height: 12.0),
|
||||
// Card(
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.circular(14.0)),
|
||||
// child: const Padding(
|
||||
// padding: EdgeInsets.all(16.0),
|
||||
// child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// Row(
|
||||
// children: [
|
||||
// Icon(FeatherIcons.alertTriangle,
|
||||
// size: 20.0, color: Colors.orange),
|
||||
// SizedBox(width: 12.0),
|
||||
// Text(
|
||||
// "Figyelem!",
|
||||
// style: TextStyle(
|
||||
// fontSize: 18.0, fontWeight: FontWeight.bold),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// SizedBox(height: 6.0),
|
||||
// Text(
|
||||
// "Az automatikus visszairányítás az alkalmazásba nem mindig működik. Ebben az esetben kérjük nyomd meg lent a \"Manuális aktiválás\" gombot!",
|
||||
// style: TextStyle(fontSize: 16.0),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
const SizedBox(height: 12.0),
|
||||
Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14.0)),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(FeatherIcons.alertTriangle,
|
||||
size: 20.0, color: Colors.orange),
|
||||
SizedBox(width: 12.0),
|
||||
Text(
|
||||
"Figyelem!",
|
||||
style: TextStyle(
|
||||
fontSize: 18.0, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 6.0),
|
||||
Text(
|
||||
"Az aktiválás azonnal történik, amint kifizetted a szolgáltatás díját. A szolgáltatás automatikusan megújul, lemondásra a beállításokban lesz lehetőséget.",
|
||||
style: TextStyle(fontSize: 16.0),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12.0),
|
||||
Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14.0)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
"Ha fizetés után a Stripe nem irányít vissza az alkalmazásba automatikusan, aktiválhatod a támogatásod a munkamenet azonosítóval, melyet kimásolhatsz a hibás URL \"session_id\" paraméteréből.",
|
||||
style:
|
||||
TextStyle(fontSize: 15.0, fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 6.0),
|
||||
Center(
|
||||
child: TextButton.icon(
|
||||
onPressed: onManualActivation,
|
||||
style: ButtonStyle(
|
||||
foregroundColor: WidgetStatePropertyAll(
|
||||
Theme.of(context).colorScheme.secondary),
|
||||
overlayColor: WidgetStatePropertyAll(Theme.of(context)
|
||||
.colorScheme
|
||||
.secondary
|
||||
.withOpacity(.1)),
|
||||
),
|
||||
icon: manualActivationLoading
|
||||
? const SizedBox(
|
||||
height: 16.0,
|
||||
width: 16.0,
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: const Icon(FeatherIcons.key, size: 20.0),
|
||||
label: const Padding(
|
||||
padding: EdgeInsets.only(left: 8.0),
|
||||
child: Text(
|
||||
"Aktiválás azonosítóval",
|
||||
style: TextStyle(fontSize: 16.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 24.0),
|
||||
child: Center(
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
WidgetStatePropertyAll(AppColors.of(context).text),
|
||||
overlayColor: WidgetStatePropertyAll(
|
||||
AppColors.of(context).text.withOpacity(.1)),
|
||||
),
|
||||
icon: const Icon(FeatherIcons.arrowLeft, size: 20.0),
|
||||
label: const Text(
|
||||
"Vissza",
|
||||
style: TextStyle(fontSize: 16.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
97
lib/ui/mobile/plus/activation_view/activation_view.dart
Normal file
97
lib/ui/mobile/plus/activation_view/activation_view.dart
Normal file
|
@ -0,0 +1,97 @@
|
|||
import 'package:animations/animations.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
import 'package:refilc_plus/ui/mobile/plus/activation_view/activation_dashboard.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:refilc_plus/ui/mobile/plus/plus_things.i18n.dart';
|
||||
|
||||
class PremiumActivationView extends StatefulWidget {
|
||||
const PremiumActivationView({super.key, required this.product});
|
||||
|
||||
final String product;
|
||||
|
||||
@override
|
||||
State<PremiumActivationView> createState() => _PremiumActivationViewState();
|
||||
}
|
||||
|
||||
class _PremiumActivationViewState extends State<PremiumActivationView>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController animation;
|
||||
bool activated = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
context.read<PlusProvider>().auth.initAuth(product: widget.product);
|
||||
|
||||
animation =
|
||||
AnimationController(vsync: this, duration: const Duration(seconds: 2));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
animation.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final premium = context.watch<PlusProvider>();
|
||||
|
||||
if (premium.hasPremium && !activated) {
|
||||
activated = true;
|
||||
animation.forward();
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Future.delayed(const Duration(seconds: 5)).then((value) {
|
||||
if (mounted) {
|
||||
// pop the anim
|
||||
Navigator.of(context).pop();
|
||||
// pop the plus view
|
||||
Navigator.of(context).pop();
|
||||
// show alert to save code
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
"copy_code_asap".i18n,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
backgroundColor: AppColors.of(context).background,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: PageTransitionSwitcher(
|
||||
transitionBuilder: (child, primaryAnimation, secondaryAnimation) =>
|
||||
SharedAxisTransition(
|
||||
animation: primaryAnimation,
|
||||
secondaryAnimation: secondaryAnimation,
|
||||
transitionType: SharedAxisTransitionType.horizontal,
|
||||
fillColor: Colors.transparent,
|
||||
child: child,
|
||||
),
|
||||
child: premium.hasPremium
|
||||
? Center(
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
child: Lottie.network(
|
||||
"https://assets2.lottiefiles.com/packages/lf20_wkebwzpz.json",
|
||||
controller: animation,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SafeArea(child: ActivationDashboard()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
138
lib/ui/mobile/plus/plus_things.i18n.dart
Normal file
138
lib/ui/mobile/plus/plus_things.i18n.dart
Normal file
|
@ -0,0 +1,138 @@
|
|||
import 'package:i18n_extension/i18n_extension.dart';
|
||||
|
||||
extension Localization on String {
|
||||
static final _t = Translations.byLocale("hu_hu") +
|
||||
{
|
||||
"en_en": {
|
||||
// upsell titles
|
||||
"u_title_1": "Use more accounts?",
|
||||
"u_title_2": "Want to try the updates in advance?",
|
||||
"u_title_3": "\"Hi kitty, do you have an owner?\"",
|
||||
"u_title_4": "Would you write down your tasks?",
|
||||
"u_title_5": "Lazy to do maths?",
|
||||
"u_title_6": "I know, the plain grey is not very nice :P",
|
||||
"u_title_7":
|
||||
"\"What were we doing in class? Was there English homework??\"",
|
||||
"u_title_8": "Now that's something special!",
|
||||
"u_title_9": "Woah! What beautiful letters!",
|
||||
"u_title_10": "Need more suggestions?",
|
||||
"u_title_11": "Not epic, but ultra-super?",
|
||||
"u_title_12": "Do you even need it in your calendar?!",
|
||||
"u_title_13": "Wanna see your past years' grades?",
|
||||
// upsell descriptions
|
||||
"u_desc_1": "The limit increases with each tier.",
|
||||
"u_desc_2":
|
||||
"Subscribe to reFilc+ to receive beta updates in advance.",
|
||||
"u_desc_3": "For a unique greeting, just the lowest tier is enough!",
|
||||
"u_desc_4":
|
||||
"Support us and make a note of all your important things.",
|
||||
"u_desc_5":
|
||||
"reFilc+ makes it easier to calculate your projected average.",
|
||||
"u_desc_6": "With Gold tier, you can recolour to anything.",
|
||||
"u_desc_7": "No more questions in Gold.",
|
||||
"u_desc_8": "Upgrade to Gold to change the app icon.",
|
||||
"u_desc_9": "You can also change the font with Gold tier.",
|
||||
"u_desc_10":
|
||||
"Support us on Gold tier and use all the features of goal setting!",
|
||||
"u_desc_11": "With reFilc+ lowest tier it's also available!",
|
||||
"u_desc_12": "Sync your time-table with reFilc+ Gold!",
|
||||
"u_desc_13": "You can export every year's grades with reFilc+!",
|
||||
// button
|
||||
"subscribe": "Subscribe",
|
||||
"subscriber": "Subscribed",
|
||||
// other
|
||||
"copy_code_asap":
|
||||
"Copy your reFilc+ ID, in case you loose your device!",
|
||||
},
|
||||
"hu_hu": {
|
||||
// upsell titles
|
||||
"u_title_1": "Több fiókot használnál?",
|
||||
"u_title_2": "Előre kipróbálnád a frissítéseket?",
|
||||
"u_title_3": "\"Szia cica, van gazdád?\"",
|
||||
"u_title_4": "Felírnád a feladataid?",
|
||||
"u_title_5": "Lusta vagy matekozni?",
|
||||
"u_title_6": "Tudom, nem túl szép a sima szürke :P",
|
||||
"u_title_7": "\"Mit is csináltunk órán? Volt angol házi??\"",
|
||||
"u_title_8": "Ez aztán különleges!",
|
||||
"u_title_9": "Woah! Micsoda gyönyörű betűk!",
|
||||
"u_title_10": "Még több javaslat kell?",
|
||||
"u_title_11": "Nem epikus, hanem ultraszuper?",
|
||||
"u_title_12": "Még a naptáradba is kell?!",
|
||||
"u_title_13": "Szeretnéd látni az előző évi jegyeid?",
|
||||
// upsell descriptions
|
||||
"u_desc_1": "Minden támogatási szinttel egyre magasabb a limit.",
|
||||
"u_desc_2":
|
||||
"Fizess elő reFilc+-ra, hogy előre megkapd a béta frissítéseket.",
|
||||
"u_desc_3": "Az egyedi üdvözléshez elég csupán a legalsó szint!",
|
||||
"u_desc_4": "Támogass minket, és jegyezd fel minden fontos dolgod.",
|
||||
"u_desc_5": "reFilc+-al egyszerűbb kiszámolnod a tervezett átlagod.",
|
||||
"u_desc_6": "Gold szintű támogatással átszínezhetsz bármilyenre.",
|
||||
"u_desc_7": "Nincs több ilyen kérdés, ha Gold szinten támogatsz.",
|
||||
"u_desc_8":
|
||||
"Fizess elő Gold szintre az alkalmazás ikonjának megváltoztatásához.",
|
||||
"u_desc_9":
|
||||
"Gold szintű támogatással megváltoztathatod a betűtípust is.",
|
||||
"u_desc_10":
|
||||
"Támogass Gold szinten és használd ki a cél kitűzés minden funkcióját!",
|
||||
"u_desc_11": "A reFilc+ alap szintjével ez is elérhető!",
|
||||
"u_desc_12": "Szinkronizáld az órarended reFilc+ Gold-al!",
|
||||
"u_desc_13": "Minden évi jegyedet exportálhatod reFilc+-al!",
|
||||
// button
|
||||
"subscribe": "Előfizetés",
|
||||
"subscriber": "Előfizetve",
|
||||
// other
|
||||
"copy_code_asap":
|
||||
"Másold ki a reFilc+ ID-t, mielőtt elveszítenéd a telefonod!",
|
||||
},
|
||||
"de_de": {
|
||||
// upsell titles
|
||||
"u_title_1": "Mehr Accounts nutzen?",
|
||||
"u_title_2": "Willst du die Updates im vorraus testen?",
|
||||
"u_title_3": "\"Hallo mein Kätzchen, hast du einen besitzer?\"",
|
||||
"u_title_4": "Würdest du deine Aufgaben aufschreiben?",
|
||||
"u_title_5": "Faul um Mathe zu machen?",
|
||||
"u_title_6": "Ich weiß, das schlichte Grau ist nicht so toll :P",
|
||||
"u_title_7":
|
||||
"\"Was haben wir im Unterricht gemacht? Gab es Englisch Hausaufgaben??\"",
|
||||
"u_title_8": "Na das ist mal was besonderes!",
|
||||
"u_title_9": "Wow! Was für schöne Texte!",
|
||||
"u_title_10": "Brauchst du mehr Vorschläge?",
|
||||
"u_title_11":
|
||||
"Willst du vielleicht statt episch etwas anderes wie super?",
|
||||
"u_title_12": "Brauchst du das wirklich in deinem Kalender?!",
|
||||
"u_title_13": "Möchtest du deine Noten der vergangenen Jahre sehen?",
|
||||
// upsell descriptions
|
||||
"u_desc_1": "Das limit erhöht sich mit jedem Abo-plan.",
|
||||
"u_desc_2":
|
||||
"Abonniere reFilc+ um Beta Updates im vorraus zu erhalten.",
|
||||
"u_desc_3":
|
||||
"Für eine eigene Begrüßung ist der niedrigste Abo-Plan schon genug!",
|
||||
"u_desc_4":
|
||||
"Unterstütze uns und schreib alles wichtige für dich auf.",
|
||||
"u_desc_5":
|
||||
"reFilc+ macht es einfacher deinen Durchschnitt zu berechnen.",
|
||||
"u_desc_6": "Mit dem Gold-Plan, kannst du alles anders Färben.",
|
||||
"u_desc_7": "Keine weiteren Fragen mit Gold.",
|
||||
"u_desc_8": "Upgrade auf Gold um das App Icon zu ändern.",
|
||||
"u_desc_9":
|
||||
"Du kannst mit dem Gold-Plan auch die Schriftart verändern.",
|
||||
"u_desc_10":
|
||||
"Unterstütze uns mit einem Gold-Plan und benutze alle features des Ziel-setzens!",
|
||||
"u_desc_11":
|
||||
"Mit reFilc+ niedrigstem Abo-Plan ist es auch Verfügbar!",
|
||||
"u_desc_12": "Synchronisiere deinen Stundenplan mit reFilc+ Gold!",
|
||||
"u_desc_13": "Du kannst jede Jahresnote mit reFilc+ exportieren!",
|
||||
// button
|
||||
"subscribe": "Abonnieren",
|
||||
"subscriber": "im Abonnement",
|
||||
// other
|
||||
"copy_code_asap":
|
||||
"Kopieren Sie Ihre reFilc+ ID, bevor Sie Ihr Handy verlieren!",
|
||||
},
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
74
lib/ui/mobile/plus/premium_inline.dart
Normal file
74
lib/ui/mobile/plus/premium_inline.dart
Normal file
|
@ -0,0 +1,74 @@
|
|||
// ignore_for_file: unused_element
|
||||
|
||||
import 'package:refilc_plus/ui/mobile/plus/upsell.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum PremiumInlineFeature { nickname, theme, widget, goal, stats }
|
||||
|
||||
const Map<PremiumInlineFeature, String> _featureAssets = {
|
||||
PremiumInlineFeature.nickname:
|
||||
"assets/images/premium_nickname_inline_showcase.png",
|
||||
PremiumInlineFeature.theme: "assets/images/premium_theme_inline_showcase.png",
|
||||
PremiumInlineFeature.widget:
|
||||
"assets/images/premium_widget_inline_showcase.png",
|
||||
PremiumInlineFeature.goal: "assets/images/premium_goal_inline_showcase.png",
|
||||
PremiumInlineFeature.stats: "assets/images/premium_stats_inline_showcase.png",
|
||||
};
|
||||
|
||||
const Map<PremiumInlineFeature, PremiumFeature> _featuresInline = {
|
||||
PremiumInlineFeature.nickname: PremiumFeature.profile,
|
||||
PremiumInlineFeature.theme: PremiumFeature.customcolors,
|
||||
PremiumInlineFeature.widget: PremiumFeature.widget,
|
||||
// PremiumInlineFeature.goal: PremiumFeature.goalplanner,
|
||||
PremiumInlineFeature.stats: PremiumFeature.gradestats,
|
||||
};
|
||||
|
||||
class PremiumInline extends StatelessWidget {
|
||||
const PremiumInline({super.key, required this.features});
|
||||
|
||||
final List<PremiumInlineFeature> features;
|
||||
|
||||
String _getAsset() {
|
||||
for (int i = 0; i < features.length; i++) {
|
||||
if (DateTime.now().day % features.length == i) {
|
||||
return _featureAssets[features[i]]!;
|
||||
}
|
||||
}
|
||||
|
||||
return _featureAssets[features[0]]!;
|
||||
}
|
||||
|
||||
PremiumFeature _getFeature() {
|
||||
for (int i = 0; i < features.length; i++) {
|
||||
if (DateTime.now().day % features.length == i) {
|
||||
return _featuresInline[features[i]]!;
|
||||
}
|
||||
}
|
||||
|
||||
return _featuresInline[features[0]]!;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SizedBox(
|
||||
height: 0,
|
||||
);
|
||||
// return Stack(
|
||||
// children: [
|
||||
// Image.asset(_getAsset()),
|
||||
// Positioned.fill(
|
||||
// child: Material(
|
||||
// type: MaterialType.transparency,
|
||||
// child: InkWell(
|
||||
// borderRadius: BorderRadius.circular(16.0),
|
||||
// onTap: () {
|
||||
// PlusLockedFeaturePopup.show(
|
||||
// context: context, feature: _getFeature());
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
}
|
||||
}
|
91
lib/ui/mobile/plus/settings_inline.dart
Normal file
91
lib/ui/mobile/plus/settings_inline.dart
Normal file
|
@ -0,0 +1,91 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:refilc_mobile_ui/plus/plus_screen.dart';
|
||||
import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
import 'plus_things.i18n.dart';
|
||||
import 'package:refilc_mobile_ui/screens/settings/settings_helper.dart';
|
||||
|
||||
class PlusSettingsInline extends StatelessWidget {
|
||||
const PlusSettingsInline({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String plusTier = Provider.of<PlusProvider>(context)
|
||||
.hasScope(PremiumScopes.tierGold)
|
||||
? 'gold'
|
||||
: (Provider.of<PlusProvider>(context).hasScope(PremiumScopes.tierBasic)
|
||||
? 'basic'
|
||||
: 'none');
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (plusTier == 'none') {
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.push(MaterialPageRoute(builder: (context) {
|
||||
return const PlusScreen();
|
||||
}));
|
||||
} else {
|
||||
SettingsHelper.plusOptions(context);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: plusTier == 'gold'
|
||||
? const AssetImage('assets/images/btn_plus_gold.png')
|
||||
: const AssetImage('assets/images/btn_plus_standard.png'),
|
||||
fit: BoxFit.fitWidth,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 2.0,
|
||||
),
|
||||
Image.asset(
|
||||
plusTier == 'gold'
|
||||
? 'assets/images/plus_tier_ink.png'
|
||||
: 'assets/images/plus_tier_cap.png',
|
||||
width: 23.0,
|
||||
height: 23.0,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 14.0,
|
||||
),
|
||||
Text(
|
||||
'reFilc+',
|
||||
style: TextStyle(
|
||||
color: plusTier == 'gold'
|
||||
? const Color(0xFF341C01)
|
||||
: const Color(0xFF150D4E),
|
||||
fontSize: 18.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
plusTier == 'none' ? '0.99 €' : 'subscriber'.i18n,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF150D4E),
|
||||
fontSize: 15.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
486
lib/ui/mobile/plus/upsell.dart
Normal file
486
lib/ui/mobile/plus/upsell.dart
Normal file
|
@ -0,0 +1,486 @@
|
|||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:refilc_mobile_ui/common/bottom_sheet_menu/rounded_bottom_sheet.dart';
|
||||
import 'package:refilc_mobile_ui/plus/plus_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'plus_things.i18n.dart';
|
||||
|
||||
enum PremiumFeature {
|
||||
// old things
|
||||
gradestats,
|
||||
customcolors,
|
||||
profile,
|
||||
iconpack,
|
||||
subjectrename,
|
||||
weeklytimetable,
|
||||
widget,
|
||||
// new things
|
||||
moreAccounts, // cap, (ink, sponge)
|
||||
betaReleases, // cap
|
||||
welcomeMessage, // cap
|
||||
selfNotes, // cap
|
||||
gradeCalculation, // ink
|
||||
liveActivity, // ink
|
||||
timetableNotes, // ink
|
||||
iconChange, // sponge
|
||||
fontChange, // sponge
|
||||
goalPlanner, // sponge
|
||||
gradeRarities,
|
||||
calendarSync,
|
||||
gradeExporting, // basic
|
||||
}
|
||||
|
||||
enum PremiumFeatureLevel {
|
||||
old,
|
||||
cap,
|
||||
ink,
|
||||
sponge,
|
||||
// new new new
|
||||
basic,
|
||||
gold,
|
||||
}
|
||||
|
||||
const Map<PremiumFeature, PremiumFeatureLevel> _featureLevels = {
|
||||
// old things
|
||||
PremiumFeature.gradestats: PremiumFeatureLevel.old,
|
||||
PremiumFeature.customcolors: PremiumFeatureLevel.old,
|
||||
PremiumFeature.profile: PremiumFeatureLevel.old,
|
||||
PremiumFeature.iconpack: PremiumFeatureLevel.old,
|
||||
PremiumFeature.subjectrename: PremiumFeatureLevel.old,
|
||||
PremiumFeature.weeklytimetable: PremiumFeatureLevel.old,
|
||||
PremiumFeature.widget: PremiumFeatureLevel.old,
|
||||
// new things
|
||||
PremiumFeature.moreAccounts: PremiumFeatureLevel.basic,
|
||||
PremiumFeature.betaReleases: PremiumFeatureLevel.basic,
|
||||
PremiumFeature.welcomeMessage: PremiumFeatureLevel.basic,
|
||||
PremiumFeature.selfNotes: PremiumFeatureLevel.basic,
|
||||
PremiumFeature.gradeCalculation: PremiumFeatureLevel.basic,
|
||||
PremiumFeature.liveActivity: PremiumFeatureLevel.gold,
|
||||
PremiumFeature.timetableNotes: PremiumFeatureLevel.gold,
|
||||
PremiumFeature.iconChange: PremiumFeatureLevel.gold,
|
||||
PremiumFeature.fontChange: PremiumFeatureLevel.gold,
|
||||
PremiumFeature.goalPlanner: PremiumFeatureLevel.gold,
|
||||
PremiumFeature.gradeRarities: PremiumFeatureLevel.basic,
|
||||
PremiumFeature.calendarSync: PremiumFeatureLevel.gold,
|
||||
PremiumFeature.gradeExporting: PremiumFeatureLevel.basic,
|
||||
};
|
||||
|
||||
// const Map<PremiumFeature, String> _featureAssets = {
|
||||
// // old
|
||||
// PremiumFeature.gradestats: "assets/images/premium_stats_showcase.png",
|
||||
// PremiumFeature.customcolors: "assets/images/premium_theme_showcase.png",
|
||||
// PremiumFeature.profile: "assets/images/premium_nickname_showcase.png",
|
||||
// PremiumFeature.weeklytimetable:
|
||||
// "assets/images/premium_timetable_showcase.png",
|
||||
// // PremiumFeature.goalplanner: "assets/images/premium_goal_showcase.png",
|
||||
// PremiumFeature.widget: "assets/images/premium_widget_showcase.png",
|
||||
// // new
|
||||
// PremiumFeature.moreAccounts: "assets/images/premium_banner/more_accounts.png",
|
||||
// PremiumFeature.betaReleases: "assets/images/premium_banner/beta_releases.png",
|
||||
// PremiumFeature.welcomeMessage:
|
||||
// "assets/images/premium_banner/welcome_message.png",
|
||||
// PremiumFeature.selfNotes: "assets/images/premium_banner/self_notes.png",
|
||||
// PremiumFeature.gradeCalculation:
|
||||
// "assets/images/premium_banner/grade_calc.png",
|
||||
// PremiumFeature.liveActivity: "assets/images/premium_banner/live_activity.png",
|
||||
// PremiumFeature.timetableNotes:
|
||||
// "assets/images/premium_banner/timetable_notes.png",
|
||||
// PremiumFeature.iconChange: "assets/images/premium_banner/app_icon.png",
|
||||
// PremiumFeature.fontChange: "assets/images/premium_banner/font.png",
|
||||
// PremiumFeature.goalPlanner: "assets/images/premium_banner/goal_planner.png",
|
||||
|
||||
// PremiumFeature.gradeRarities:
|
||||
// "assets/images/premium_banner/grade_rarities.png",
|
||||
// PremiumFeature.calendarSync: "assets/images/premium_banner/calendar_sync.png",
|
||||
// };
|
||||
|
||||
const Map<PremiumFeature, String> _featureTitles = {
|
||||
// old shit
|
||||
PremiumFeature.gradestats: "Találtál egy prémium funkciót.",
|
||||
PremiumFeature.customcolors: "Több személyre szabás kell?",
|
||||
PremiumFeature.profile: "Nem tetszik a neved?",
|
||||
PremiumFeature.iconpack: "Jobban tetszettek a régi ikonok?",
|
||||
PremiumFeature.subjectrename:
|
||||
"Sokáig tart elolvasni, hogy \"Földrajz természettudomány\"?",
|
||||
PremiumFeature.weeklytimetable: "Szeretnéd egyszerre az egész hetet látni?",
|
||||
// PremiumFeature.goalplanner: "Kövesd a céljaidat, sok-sok statisztikával.",
|
||||
PremiumFeature.widget: "Órák a kezdőképernyőd kényelméből.",
|
||||
// new shit
|
||||
PremiumFeature.moreAccounts: "u_title_1",
|
||||
PremiumFeature.betaReleases: "u_title_2",
|
||||
PremiumFeature.welcomeMessage: "u_title_3",
|
||||
PremiumFeature.selfNotes: "u_title_4",
|
||||
PremiumFeature.gradeCalculation: "u_title_5",
|
||||
PremiumFeature.liveActivity: "u_title_6",
|
||||
PremiumFeature.timetableNotes: "u_title_7",
|
||||
PremiumFeature.iconChange: "u_title_8",
|
||||
PremiumFeature.fontChange: "u_title_9",
|
||||
PremiumFeature.goalPlanner: "u_title_10",
|
||||
PremiumFeature.gradeRarities: "u_title_11",
|
||||
PremiumFeature.calendarSync: "u_title_12",
|
||||
PremiumFeature.gradeExporting: "u_title_13",
|
||||
};
|
||||
|
||||
const Map<PremiumFeature, String> _featureDescriptions = {
|
||||
// old
|
||||
PremiumFeature.gradestats:
|
||||
"Támogass Kupak szinten, hogy több statisztikát láthass. ",
|
||||
PremiumFeature.customcolors:
|
||||
"Támogass Kupak szinten, és szabd személyre az elemek, a háttér, és a panelek színeit.",
|
||||
PremiumFeature.profile:
|
||||
"Kupak szinten változtathatod a nevedet, sőt, akár a profilképedet is.",
|
||||
PremiumFeature.iconpack:
|
||||
"Támogass Kupak szinten, hogy ikon témát választhass.",
|
||||
PremiumFeature.subjectrename:
|
||||
"Támogass Kupak szinten, hogy átnevezhesd Föcire.",
|
||||
PremiumFeature.weeklytimetable:
|
||||
"Támogass Tinta szinten a heti órarend funkcióért.",
|
||||
// PremiumFeature.goalplanner: "A célkövetéshez támogass Tinta szinten.",
|
||||
PremiumFeature.widget:
|
||||
"Támogass Tinta szinten, és helyezz egy widgetet a kezdőképernyődre.",
|
||||
// new
|
||||
PremiumFeature.moreAccounts: "u_desc_1",
|
||||
PremiumFeature.betaReleases: "u_desc_2",
|
||||
PremiumFeature.welcomeMessage: "u_desc_3",
|
||||
PremiumFeature.selfNotes: "u_desc_4",
|
||||
PremiumFeature.gradeCalculation: "u_desc_5",
|
||||
PremiumFeature.liveActivity: "u_desc_6",
|
||||
PremiumFeature.timetableNotes: "u_desc_7",
|
||||
PremiumFeature.iconChange: "u_desc_8",
|
||||
PremiumFeature.fontChange: "u_desc_9",
|
||||
PremiumFeature.goalPlanner: "u_desc_10",
|
||||
PremiumFeature.gradeRarities: "u_desc_11",
|
||||
PremiumFeature.calendarSync: "u_desc_12",
|
||||
PremiumFeature.gradeExporting: "u_desc_13",
|
||||
};
|
||||
|
||||
// class PremiumLockedFeatureUpsell extends StatelessWidget {
|
||||
// const PremiumLockedFeatureUpsell({super.key, required this.feature});
|
||||
|
||||
// static void show(
|
||||
// {required BuildContext context, required PremiumFeature feature}) =>
|
||||
// showRoundedModalBottomSheet(context,
|
||||
// child: PremiumLockedFeatureUpsell(feature: feature));
|
||||
|
||||
// final PremiumFeature feature;
|
||||
|
||||
// IconData _getIcon() => _featureLevels[feature] == PremiumFeatureLevel.cap
|
||||
// ? FilcIcons.kupak
|
||||
// : _featureLevels[feature] == PremiumFeatureLevel.ink
|
||||
// ? FilcIcons.tinta
|
||||
// : FilcIcons.tinta;
|
||||
// Color _getColor(BuildContext context) =>
|
||||
// _featureLevels[feature] == PremiumFeatureLevel.gold
|
||||
// ? const Color(0xFFC89B08)
|
||||
// : Theme.of(context).brightness == Brightness.light
|
||||
// ? const Color(0xff691A9B)
|
||||
// : const Color(0xffA66FC8);
|
||||
// String? _getAsset() => _featureAssets[feature];
|
||||
// String _getTitle() => _featureTitles[feature]!;
|
||||
// String _getDescription() => _featureDescriptions[feature]!;
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// final Color color = _getColor(context);
|
||||
|
||||
// return Dialog(
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 16.0),
|
||||
// child: Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// // Title Bar
|
||||
// Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// children: [
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(left: 8.0),
|
||||
// child: Icon(_getIcon()),
|
||||
// ),
|
||||
// IconButton(
|
||||
// onPressed: () => Navigator.of(context).pop(),
|
||||
// icon: const Icon(Icons.close),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
|
||||
// // Image showcase
|
||||
// if (_getAsset() != null)
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(top: 8.0),
|
||||
// child: Image.asset(_getAsset()!),
|
||||
// ),
|
||||
|
||||
// // Dialog title
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(top: 12.0),
|
||||
// child: Text(
|
||||
// _getTitle(),
|
||||
// style: const TextStyle(
|
||||
// fontWeight: FontWeight.bold,
|
||||
// fontSize: 20.0,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
|
||||
// // Dialog description
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(top: 8.0),
|
||||
// child: Text(
|
||||
// _getDescription(),
|
||||
// style: const TextStyle(
|
||||
// fontSize: 16.0,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
|
||||
// // CTA button
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(top: 8.0),
|
||||
// child: SizedBox(
|
||||
// width: double.infinity,
|
||||
// child: TextButton(
|
||||
// style: ButtonStyle(
|
||||
// backgroundColor:
|
||||
// WidgetStatePropertyAll(color.withOpacity(.25)),
|
||||
// foregroundColor: WidgetStatePropertyAll(color),
|
||||
// overlayColor:
|
||||
// WidgetStatePropertyAll(color.withOpacity(.1))),
|
||||
// onPressed: () {
|
||||
// Navigator.of(context, rootNavigator: true)
|
||||
// .push(MaterialPageRoute(builder: (context) {
|
||||
// return const PlusScreen();
|
||||
// }));
|
||||
// },
|
||||
// child: const Text(
|
||||
// "Vigyél oda!",
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.bold,
|
||||
// fontSize: 18.0,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
class PlusLockedFeaturePopup extends StatelessWidget {
|
||||
const PlusLockedFeaturePopup({super.key, required this.feature});
|
||||
|
||||
static void show({
|
||||
required BuildContext context,
|
||||
required PremiumFeature feature,
|
||||
}) =>
|
||||
showRoundedModalBottomSheet(
|
||||
context,
|
||||
child: PlusLockedFeaturePopup(
|
||||
feature: feature,
|
||||
),
|
||||
showHandle: false,
|
||||
);
|
||||
|
||||
final PremiumFeature feature;
|
||||
|
||||
PremiumFeatureLevel? _getFeatureLevel() => _featureLevels[feature];
|
||||
|
||||
// IconData _getIcon() => _featureLevels[feature] == PremiumFeatureLevel.cap
|
||||
// ? FilcIcons.kupak
|
||||
// : _featureLevels[feature] == PremiumFeatureLevel.ink
|
||||
// ? FilcIcons.tinta
|
||||
// : FilcIcons.tinta;
|
||||
// Color _getColor(BuildContext context) =>
|
||||
// _featureLevels[feature] == PremiumFeatureLevel.gold
|
||||
// ? const Color(0xFFC89B08)
|
||||
// : Theme.of(context).brightness == Brightness.light
|
||||
// ? const Color(0xff691A9B)
|
||||
// : const Color(0xffA66FC8);
|
||||
// String? _getAsset() => _featureAssets[feature];
|
||||
String _getTitle() => _featureTitles[feature]!.i18n;
|
||||
String _getDescription() => _featureDescriptions[feature]!.i18n;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isGold = _getFeatureLevel() == PremiumFeatureLevel.gold;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isGold ? const Color(0xFFF7EDD9) : const Color(0xFFDCDAF7),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12.0),
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
// "assets/svg/mesh_bg.svg",
|
||||
"assets/svg/cover_arts/grid.svg",
|
||||
// ignore: deprecated_member_use
|
||||
color: isGold ? const Color(0xFFf0dcb6) : const Color(0xFFbcb8f0),
|
||||
width: MediaQuery.of(context).size.width,
|
||||
),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(18.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: isGold
|
||||
? const Color(0xFF341C01)
|
||||
: const Color(0xFF130667),
|
||||
borderRadius: BorderRadius.circular(
|
||||
2.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 38.0,
|
||||
),
|
||||
Image.asset(
|
||||
'assets/images/plus_${isGold ? 'gold' : 'standard'}.png',
|
||||
width: 66,
|
||||
height: 66,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 55.0,
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(
|
||||
0xFFF7F9FC,
|
||||
).withOpacity(0.7),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12.0),
|
||||
bottom: Radius.circular(6.0),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(14.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
isGold ? 'reFilc+ Gold' : 'reFilc+',
|
||||
style: TextStyle(
|
||||
color: isGold
|
||||
? const Color(0xFFAD7637)
|
||||
: const Color(0xFF7463E2),
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 12.0,
|
||||
),
|
||||
Text(
|
||||
_getTitle(),
|
||||
style: TextStyle(
|
||||
color: isGold
|
||||
? const Color(0xFF341C01)
|
||||
: const Color(0xFF150D4E),
|
||||
fontSize: 20.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 8.0,
|
||||
),
|
||||
Text(
|
||||
_getDescription(),
|
||||
style: TextStyle(
|
||||
color: isGold
|
||||
? const Color(0xFF341C01)
|
||||
: const Color(0xFF150D4E),
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 6.0,
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(
|
||||
0xFFF7F9FC,
|
||||
).withOpacity(0.7),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(6.0),
|
||||
bottom: Radius.circular(12.0),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(14.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'A reFilc+ 0.99 €, a reFilc+ Gold 2.99 €',
|
||||
style: TextStyle(
|
||||
color: isGold
|
||||
? const Color(0xFF341C01)
|
||||
: const Color(0xFF150D4E),
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 24.0,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.push(MaterialPageRoute(builder: (context) {
|
||||
return const PlusScreen();
|
||||
}));
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
'assets/images/btn_plus_${isGold ? 'gold' : 'standard'}.png'),
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'subscribe'.i18n,
|
||||
style: TextStyle(
|
||||
color: isGold
|
||||
? const Color(0xFF341C01)
|
||||
: const Color(0xFF150D4E),
|
||||
fontSize: 18.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
242
lib/ui/mobile/settings/app_icon_screen.dart
Normal file
242
lib/ui/mobile/settings/app_icon_screen.dart
Normal file
|
@ -0,0 +1,242 @@
|
|||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_mobile_ui/common/panel/panel.dart';
|
||||
// import 'package:refilc_mobile_ui/common/panel/panel_button.dart';
|
||||
import 'package:refilc_plus/helpers/app_icon_helper.dart';
|
||||
// import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
// import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
// import 'package:refilc_plus/ui/mobile/plus/upsell.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'app_icon_screen.i18n.dart';
|
||||
|
||||
class PremiumCustomAppIconMenu extends StatelessWidget {
|
||||
const PremiumCustomAppIconMenu({super.key, required this.settings});
|
||||
|
||||
final SettingsProvider settings;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// return PanelButton(
|
||||
// onPressed: () {
|
||||
// if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
// .hasScope(PremiumScopes.changeAppIcon)) {
|
||||
// PlusLockedFeaturePopup.show(
|
||||
// context: context, feature: PremiumFeature.appiconchange);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Navigator.of(context, rootNavigator: true).push(
|
||||
// CupertinoPageRoute(builder: (context) => const ModifyAppIcon()),
|
||||
// );
|
||||
// },
|
||||
// title: Text('custom_app_icon'.i18n),
|
||||
// leading: const Icon(FeatherIcons.edit),
|
||||
// );
|
||||
return const SizedBox(
|
||||
width: 0,
|
||||
height: 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ModifyAppIcon extends StatefulWidget {
|
||||
const ModifyAppIcon({super.key});
|
||||
|
||||
@override
|
||||
State<ModifyAppIcon> createState() => _ModifyAppIconState();
|
||||
}
|
||||
|
||||
class _ModifyAppIconState extends State<ModifyAppIcon> {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
late SettingsProvider settings;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
settings = Provider.of<SettingsProvider>(context);
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: AppBar(
|
||||
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
leading: BackButton(color: AppColors.of(context).text),
|
||||
title: Text(
|
||||
"app_icons".i18n,
|
||||
style: TextStyle(color: AppColors.of(context).text),
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Panel(
|
||||
title: Text("basic".i18n),
|
||||
child: Column(
|
||||
children: [
|
||||
AppIconItem(
|
||||
iconName: 'refilc_default',
|
||||
iconPath: 'assets/launch_icons/refilc_default.png',
|
||||
displayName: 'reFilc Default',
|
||||
description: 'Az alapértelmezett ikon.',
|
||||
selected: settings.appIcon == 'refilc_default',
|
||||
selectCallback: () async {
|
||||
await AppIconHelper.setAppIcon('refilc_default');
|
||||
settings.update(appIcon: 'refilc_default');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// const SizedBox(height: 16.0),
|
||||
// Panel(
|
||||
// title: Text("seasonal".i18n),
|
||||
// child: Column(
|
||||
// children: [
|
||||
// // AppIconItem(
|
||||
// // iconName: 'refilc_default',
|
||||
// // iconPath: 'assets/launch_icons/refilc_default.png',
|
||||
// // displayName: 'reFilc Default',
|
||||
// // description: 'Az alapértelmezett ikon.',
|
||||
// // selected: true,
|
||||
// // selectCallback: () {},
|
||||
// // ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
const SizedBox(height: 16.0),
|
||||
Panel(
|
||||
title: Text("special".i18n),
|
||||
child: Column(
|
||||
children: [
|
||||
AppIconItem(
|
||||
iconName: 'refilc_overcomplicated',
|
||||
iconPath:
|
||||
'assets/launch_icons/refilc_overcomplicated.png',
|
||||
displayName: 'Overcomplicated',
|
||||
// description: 'Egy túlkomplikált ikon.',
|
||||
selected: settings.appIcon == 'refilc_overcomplicated',
|
||||
selectCallback: () async {
|
||||
await AppIconHelper.setAppIcon(
|
||||
'refilc_overcomplicated');
|
||||
settings.update(appIcon: 'refilc_overcomplicated');
|
||||
},
|
||||
),
|
||||
AppIconItem(
|
||||
iconName: 'refilc_concept',
|
||||
iconPath: 'assets/launch_icons/refilc_concept.png',
|
||||
displayName: 'Modern Concept',
|
||||
// description: 'Egy modernebb, letisztultabb ikon.',
|
||||
selected: settings.appIcon == 'refilc_concept',
|
||||
selectCallback: () async {
|
||||
await AppIconHelper.setAppIcon('refilc_concept');
|
||||
settings.update(appIcon: 'refilc_concept');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
Panel(
|
||||
title: Text("other".i18n),
|
||||
child: Column(
|
||||
children: [
|
||||
AppIconItem(
|
||||
iconName: 'refilc_pride',
|
||||
iconPath: 'assets/launch_icons/refilc_pride.png',
|
||||
displayName: 'Pride',
|
||||
// description: '',
|
||||
selected: settings.appIcon == 'refilc_pride',
|
||||
selectCallback: () async {
|
||||
await AppIconHelper.setAppIcon('refilc_pride');
|
||||
settings.update(appIcon: 'refilc_pride');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class AppIconItem extends StatelessWidget {
|
||||
const AppIconItem({
|
||||
super.key,
|
||||
required this.iconName,
|
||||
required this.iconPath,
|
||||
required this.displayName,
|
||||
this.description,
|
||||
required this.selected,
|
||||
required this.selectCallback,
|
||||
});
|
||||
|
||||
final String iconName;
|
||||
final String iconPath;
|
||||
final String displayName;
|
||||
final String? description;
|
||||
final bool selected;
|
||||
final void Function() selectCallback;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
minLeadingWidth: 32.0,
|
||||
dense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 0),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
|
||||
visualDensity: VisualDensity.compact,
|
||||
onTap: () {},
|
||||
leading: Container(
|
||||
height: 40,
|
||||
width: 40,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
image: DecorationImage(
|
||||
image: AssetImage(iconPath),
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: InkWell(
|
||||
onTap: selectCallback,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
displayName,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 16,
|
||||
height: description == null ? 3.2 : 1.8,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (description != null)
|
||||
Text(
|
||||
description!,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
color: AppColors.of(context).text.withOpacity(.75),
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
trailing: selected
|
||||
? Icon(
|
||||
FeatherIcons.checkCircle,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
)
|
||||
: const SizedBox(),
|
||||
);
|
||||
}
|
||||
}
|
36
lib/ui/mobile/settings/app_icon_screen.i18n.dart
Normal file
36
lib/ui/mobile/settings/app_icon_screen.i18n.dart
Normal file
|
@ -0,0 +1,36 @@
|
|||
import 'package:i18n_extension/i18n_extension.dart';
|
||||
|
||||
extension Localization on String {
|
||||
static final _t = Translations.byLocale("hu_hu") +
|
||||
{
|
||||
"en_en": {
|
||||
"custom_app_icon": "Custom App Icon",
|
||||
"app_icons": "App Icons",
|
||||
"basic": "Basic",
|
||||
"seasonal": "Seasonal",
|
||||
"special": "Special",
|
||||
"other": "Other",
|
||||
},
|
||||
"hu_hu": {
|
||||
"custom_app_icon": "Alkalmazásikon",
|
||||
"app_icons": "Alkalmazásikonok",
|
||||
"basic": "Egyszerű",
|
||||
"seasonal": "Szezonális",
|
||||
"special": "Különleges",
|
||||
"other": "Egyéb",
|
||||
},
|
||||
"de_de": {
|
||||
"custom_app_icon": "App-Symbol",
|
||||
"app_icons": "App-Symbole",
|
||||
"basic": "Basic",
|
||||
"seasonal": "Saisonal",
|
||||
"special": "Besonders",
|
||||
"other": "Andere",
|
||||
},
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
452
lib/ui/mobile/settings/modify_teacher_names.dart
Normal file
452
lib/ui/mobile/settings/modify_teacher_names.dart
Normal file
|
@ -0,0 +1,452 @@
|
|||
// import 'package:dropdown_button2/dropdown_button2.dart';
|
||||
// import 'package:refilc/api/providers/database_provider.dart';
|
||||
// import 'package:refilc/api/providers/user_provider.dart';
|
||||
// import 'package:refilc/models/settings.dart';
|
||||
// import 'package:refilc/theme/colors/colors.dart';
|
||||
// import 'package:refilc/utils/format.dart';
|
||||
// import 'package:refilc_kreta_api/models/teacher.dart';
|
||||
// import 'package:refilc_kreta_api/providers/absence_provider.dart';
|
||||
// import 'package:refilc_kreta_api/providers/grade_provider.dart';
|
||||
// import 'package:refilc_kreta_api/providers/timetable_provider.dart';
|
||||
// import 'package:refilc_mobile_ui/common/panel/panel.dart';
|
||||
// import 'package:refilc_mobile_ui/common/panel/panel_button.dart';
|
||||
// // import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
// // import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
// // import 'package:refilc_plus/ui/mobile/plus/upsell.dart';
|
||||
// import 'package:flutter/cupertino.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
// import 'package:provider/provider.dart';
|
||||
// import 'package:refilc_mobile_ui/screens/settings/modify_names.i18n.dart';
|
||||
|
||||
// class MenuRenamedTeachers extends StatelessWidget {
|
||||
// const MenuRenamedTeachers({Key? key, required this.settings})
|
||||
// : super(key: key);
|
||||
|
||||
// final SettingsProvider settings;
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return PanelButton(
|
||||
// padding: const EdgeInsets.only(left: 14.0),
|
||||
// onPressed: () {
|
||||
// // if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
// // .hasScope(PremiumScopes.renameTeachers)) {
|
||||
// // PlusLockedFeaturePopup.show(
|
||||
// // context: context, feature: PremiumFeature.teacherrename);
|
||||
// // return;
|
||||
// // }
|
||||
|
||||
// Navigator.of(context, rootNavigator: true).push(
|
||||
// CupertinoPageRoute(builder: (context) => const ModifyTeacherNames()),
|
||||
// );
|
||||
// },
|
||||
// title: Text(
|
||||
// "rename_teachers".i18n,
|
||||
// style: TextStyle(
|
||||
// color: AppColors.of(context)
|
||||
// .text
|
||||
// .withOpacity(settings.renamedTeachersEnabled ? 1.0 : .5)),
|
||||
// ),
|
||||
// leading: settings.renamedTeachersEnabled
|
||||
// ? const Icon(FeatherIcons.users)
|
||||
// : Icon(FeatherIcons.users,
|
||||
// color: AppColors.of(context).text.withOpacity(.25)),
|
||||
// trailingDivider: true,
|
||||
// trailing: Switch(
|
||||
// onChanged: (v) async {
|
||||
// // if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
// // .hasScope(PremiumScopes.renameTeachers)) {
|
||||
// // PlusLockedFeaturePopup.show(
|
||||
// // context: context, feature: PremiumFeature.teacherrename);
|
||||
// // return;
|
||||
// // }
|
||||
|
||||
// settings.update(renamedTeachersEnabled: v);
|
||||
// await Provider.of<GradeProvider>(context, listen: false)
|
||||
// .convertBySettings();
|
||||
// await Provider.of<TimetableProvider>(context, listen: false)
|
||||
// .convertBySettings();
|
||||
// await Provider.of<AbsenceProvider>(context, listen: false)
|
||||
// .convertBySettings();
|
||||
// },
|
||||
// value: settings.renamedTeachersEnabled,
|
||||
// activeColor: Theme.of(context).colorScheme.secondary,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// class ModifyTeacherNames extends StatefulWidget {
|
||||
// const ModifyTeacherNames({Key? key}) : super(key: key);
|
||||
|
||||
// @override
|
||||
// State<ModifyTeacherNames> createState() => _ModifyTeacherNamesState();
|
||||
// }
|
||||
|
||||
// class _ModifyTeacherNamesState extends State<ModifyTeacherNames> {
|
||||
// final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
// final _teacherName = TextEditingController();
|
||||
// String? selectedTeacherId;
|
||||
|
||||
// late List<Teacher> teachers;
|
||||
// late UserProvider user;
|
||||
// late DatabaseProvider dbProvider;
|
||||
// late SettingsProvider settings;
|
||||
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// teachers = (Provider.of<GradeProvider>(context, listen: false)
|
||||
// .grades
|
||||
// .map((e) => e.teacher)
|
||||
// .toSet()
|
||||
// .toList()
|
||||
// ..sort((a, b) => a.name.compareTo(b.name)));
|
||||
// user = Provider.of<UserProvider>(context, listen: false);
|
||||
// dbProvider = Provider.of<DatabaseProvider>(context, listen: false);
|
||||
// }
|
||||
|
||||
// Future<Map<String, String>> fetchRenamedTeachers() async {
|
||||
// return await dbProvider.userQuery.renamedTeachers(userId: user.id!);
|
||||
// }
|
||||
|
||||
// void showRenameDialog() {
|
||||
// showDialog(
|
||||
// context: context,
|
||||
// builder: (context) => StatefulBuilder(builder: (context, setS) {
|
||||
// return AlertDialog(
|
||||
// shape: const RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.all(Radius.circular(14.0))),
|
||||
// title: Text("rename_teacher".i18n),
|
||||
// content: Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// children: [
|
||||
// DropdownButton2(
|
||||
// items: teachers
|
||||
// .map((item) => DropdownMenuItem<String>(
|
||||
// value: item.id,
|
||||
// child: Text(
|
||||
// item.name,
|
||||
// style: TextStyle(
|
||||
// fontSize: 14,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: AppColors.of(context).text,
|
||||
// ),
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// ),
|
||||
// ))
|
||||
// .toList(),
|
||||
// onChanged: (String? v) async {
|
||||
// final renamedSubs = await fetchRenamedTeachers();
|
||||
|
||||
// setS(() {
|
||||
// selectedTeacherId = v;
|
||||
|
||||
// if (renamedSubs.containsKey(selectedTeacherId)) {
|
||||
// _teacherName.text = renamedSubs[selectedTeacherId]!;
|
||||
// } else {
|
||||
// _teacherName.text = "";
|
||||
// }
|
||||
// });
|
||||
// },
|
||||
// iconStyleData: IconStyleData(
|
||||
// iconSize: 14,
|
||||
// iconEnabledColor: AppColors.of(context).text,
|
||||
// iconDisabledColor: AppColors.of(context).text,
|
||||
// ),
|
||||
// underline: const SizedBox(),
|
||||
// menuItemStyleData: MenuItemStyleData(height: 40,),
|
||||
// itemHeight: 40,
|
||||
// itemPadding: const EdgeInsets.only(left: 14, right: 14),
|
||||
// buttonWidth: 50,
|
||||
// dropdownWidth: 300,
|
||||
// dropdownPadding: null,
|
||||
// buttonDecoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// ),
|
||||
// dropdownDecoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(14),
|
||||
// ),
|
||||
// dropdownElevation: 8,
|
||||
// scrollbarRadius: const Radius.circular(40),
|
||||
// scrollbarThickness: 6,
|
||||
// scrollbarAlwaysShow: true,
|
||||
// offset: const Offset(-10, -10),
|
||||
// buttonSplashColor: Colors.transparent,
|
||||
// customButton: Container(
|
||||
// width: double.infinity,
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border.all(color: Colors.grey, width: 2),
|
||||
// borderRadius: BorderRadius.circular(12.0),
|
||||
// ),
|
||||
// padding: const EdgeInsets.symmetric(
|
||||
// vertical: 12.0, horizontal: 8.0),
|
||||
// child: Text(
|
||||
// selectedTeacherId == null
|
||||
// ? "select_teacher".i18n
|
||||
// : teachers
|
||||
// .firstWhere(
|
||||
// (element) => element.id == selectedTeacherId,
|
||||
// orElse: () => Teacher(
|
||||
// id: 'noid', name: "select_teacher".i18n),
|
||||
// )
|
||||
// .name,
|
||||
// style: Theme.of(context).textTheme.titleSmall!.copyWith(
|
||||
// fontWeight: FontWeight.w700,
|
||||
// color: AppColors.of(context).text.withOpacity(0.75)),
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// maxLines: 2,
|
||||
// textAlign: TextAlign.center,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const Padding(
|
||||
// padding: EdgeInsets.symmetric(vertical: 8.0),
|
||||
// child: Icon(FeatherIcons.arrowDown, size: 32),
|
||||
// ),
|
||||
// TextField(
|
||||
// controller: _teacherName,
|
||||
// decoration: InputDecoration(
|
||||
// border: OutlineInputBorder(
|
||||
// borderSide:
|
||||
// const BorderSide(color: Colors.grey, width: 1.5),
|
||||
// borderRadius: BorderRadius.circular(12.0),
|
||||
// ),
|
||||
// focusedBorder: OutlineInputBorder(
|
||||
// borderSide:
|
||||
// const BorderSide(color: Colors.grey, width: 1.5),
|
||||
// borderRadius: BorderRadius.circular(12.0),
|
||||
// ),
|
||||
// contentPadding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
// hintText: "modified_name".i18n,
|
||||
// suffixIcon: IconButton(
|
||||
// icon: const Icon(
|
||||
// FeatherIcons.x,
|
||||
// color: Colors.grey,
|
||||
// ),
|
||||
// onPressed: () {
|
||||
// setState(() {
|
||||
// _teacherName.text = "";
|
||||
// });
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// actions: [
|
||||
// TextButton(
|
||||
// child: Text(
|
||||
// "cancel".i18n,
|
||||
// style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
// ),
|
||||
// onPressed: () {
|
||||
// Navigator.of(context).maybePop();
|
||||
// },
|
||||
// ),
|
||||
// TextButton(
|
||||
// child: Text(
|
||||
// "done".i18n,
|
||||
// style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
// ),
|
||||
// onPressed: () async {
|
||||
// if (selectedTeacherId != null) {
|
||||
// final renamedSubs = await fetchRenamedTeachers();
|
||||
|
||||
// renamedSubs[selectedTeacherId!] = _teacherName.text;
|
||||
// await dbProvider.userStore
|
||||
// .storeRenamedTeachers(renamedSubs, userId: user.id!);
|
||||
// await Provider.of<GradeProvider>(context, listen: false)
|
||||
// .convertBySettings();
|
||||
// await Provider.of<TimetableProvider>(context, listen: false)
|
||||
// .convertBySettings();
|
||||
// await Provider.of<AbsenceProvider>(context, listen: false)
|
||||
// .convertBySettings();
|
||||
// }
|
||||
// Navigator.of(context).pop(true);
|
||||
// setState(() {});
|
||||
// },
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }),
|
||||
// ).then((val) {
|
||||
// _teacherName.text = "";
|
||||
// selectedTeacherId = null;
|
||||
// });
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// settings = Provider.of<SettingsProvider>(context);
|
||||
// return Scaffold(
|
||||
// key: _scaffoldKey,
|
||||
// appBar: AppBar(
|
||||
// surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
// leading: BackButton(color: AppColors.of(context).text),
|
||||
// title: Text(
|
||||
// "modify_teachers".i18n,
|
||||
// style: TextStyle(color: AppColors.of(context).text),
|
||||
// ),
|
||||
// ),
|
||||
// body: Padding(
|
||||
// padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
||||
// child: SingleChildScrollView(
|
||||
// child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// // Panel(
|
||||
// // child: SwitchListTile(
|
||||
|
||||
// // title: Text("italics_toggle".i18n),
|
||||
// // onChanged: (value) =>
|
||||
// // settings.update(renamedTeachersItalics: value),
|
||||
// // value: settings.renamedTeachersItalics,
|
||||
// // ),
|
||||
// // ),
|
||||
// // const SizedBox(
|
||||
// // height: 20,
|
||||
// // ),
|
||||
// InkWell(
|
||||
// onTap: showRenameDialog,
|
||||
// borderRadius: BorderRadius.circular(12.0),
|
||||
// child: Container(
|
||||
// width: double.infinity,
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border.all(color: Colors.grey, width: 2),
|
||||
// borderRadius: BorderRadius.circular(12.0),
|
||||
// ),
|
||||
// padding: const EdgeInsets.symmetric(
|
||||
// vertical: 18.0, horizontal: 12.0),
|
||||
// child: Center(
|
||||
// child: Text(
|
||||
// "rename_new_teacher".i18n,
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.w600,
|
||||
// fontSize: 18,
|
||||
// color: AppColors.of(context).text.withOpacity(.85),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// height: 30,
|
||||
// ),
|
||||
// FutureBuilder<Map<String, String>>(
|
||||
// future: fetchRenamedTeachers(),
|
||||
// builder: (context, snapshot) {
|
||||
// if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
// return Container();
|
||||
// }
|
||||
|
||||
// return Panel(
|
||||
// title: Text("renamed_teachers".i18n),
|
||||
// child: Column(
|
||||
// children: snapshot.data!.keys.map(
|
||||
// (key) {
|
||||
// Teacher? teacher = teachers.firstWhere(
|
||||
// (element) => key == element.id,
|
||||
// orElse: () => Teacher(id: 'noid', name: 'noname'),
|
||||
// );
|
||||
|
||||
// if (teacher.id == 'noid') {
|
||||
// return const SizedBox(
|
||||
// width: 0,
|
||||
// height: 0,
|
||||
// );
|
||||
// }
|
||||
|
||||
// String renameTo = snapshot.data![key]!;
|
||||
// return RenamedTeacherItem(
|
||||
// teacher: teacher,
|
||||
// renamedTo: renameTo,
|
||||
// modifyCallback: () {
|
||||
// setState(() {
|
||||
// selectedTeacherId = teacher.id;
|
||||
// _teacherName.text = renameTo;
|
||||
// });
|
||||
// showRenameDialog();
|
||||
// },
|
||||
// removeCallback: () {
|
||||
// setState(() {
|
||||
// Map<String, String> subs =
|
||||
// Map.from(snapshot.data!);
|
||||
// subs.remove(key);
|
||||
// dbProvider.userStore.storeRenamedTeachers(
|
||||
// subs,
|
||||
// userId: user.id!);
|
||||
// });
|
||||
// },
|
||||
// );
|
||||
// },
|
||||
// ).toList(),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
|
||||
// class RenamedTeacherItem extends StatelessWidget {
|
||||
// const RenamedTeacherItem({
|
||||
// Key? key,
|
||||
// required this.teacher,
|
||||
// required this.renamedTo,
|
||||
// required this.modifyCallback,
|
||||
// required this.removeCallback,
|
||||
// }) : super(key: key);
|
||||
|
||||
// final Teacher teacher;
|
||||
// final String renamedTo;
|
||||
// final void Function() modifyCallback;
|
||||
// final void Function() removeCallback;
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return ListTile(
|
||||
// minLeadingWidth: 32.0,
|
||||
// dense: true,
|
||||
// contentPadding:
|
||||
// const EdgeInsets.symmetric(horizontal: 16.0, vertical: 6.0),
|
||||
// shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
|
||||
// visualDensity: VisualDensity.compact,
|
||||
// onTap: () {},
|
||||
// leading: Icon(FeatherIcons.user,
|
||||
// color: AppColors.of(context).text.withOpacity(.75)),
|
||||
// title: InkWell(
|
||||
// onTap: modifyCallback,
|
||||
// child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// Text(
|
||||
// teacher.name.capital(),
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.w500,
|
||||
// fontSize: 14,
|
||||
// color: AppColors.of(context).text.withOpacity(.75)),
|
||||
// maxLines: 1,
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// ),
|
||||
// Text(
|
||||
// renamedTo,
|
||||
// style: const TextStyle(fontWeight: FontWeight.w500, fontSize: 16),
|
||||
// maxLines: 2,
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// trailing: InkWell(
|
||||
// onTap: removeCallback,
|
||||
// child: Icon(FeatherIcons.trash,
|
||||
// color: AppColors.of(context).red.withOpacity(.75)),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
143
lib/ui/mobile/settings/settings_helper.dart
Normal file
143
lib/ui/mobile/settings/settings_helper.dart
Normal file
|
@ -0,0 +1,143 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.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/models/settings.dart';
|
||||
import 'package:refilc/ui/widgets/grade/grade_tile.dart';
|
||||
import 'package:refilc_kreta_api/models/grade.dart';
|
||||
|
||||
class GradeRarityTextSetting extends StatefulWidget {
|
||||
const GradeRarityTextSetting({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.cancel,
|
||||
required this.done,
|
||||
required this.defaultRarities,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String cancel;
|
||||
final String done;
|
||||
final List<String> defaultRarities;
|
||||
|
||||
@override
|
||||
GradeRarityTextSettingState createState() => GradeRarityTextSettingState();
|
||||
}
|
||||
|
||||
class GradeRarityTextSettingState extends State<GradeRarityTextSetting> {
|
||||
late SettingsProvider settings;
|
||||
late DatabaseProvider db;
|
||||
late UserProvider user;
|
||||
|
||||
final _rarityText = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
db = Provider.of<DatabaseProvider>(context, listen: false);
|
||||
user = Provider.of<UserProvider>(context, listen: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: List.generate(5, (index) {
|
||||
return ClipOval(
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
showRenameDialog(
|
||||
title: widget.title,
|
||||
cancel: widget.cancel,
|
||||
done: widget.done,
|
||||
rarities:
|
||||
await db.userQuery.getGradeRarities(userId: user.id!),
|
||||
gradeIndex: (index + 1).toString(),
|
||||
defaultRarities: widget.defaultRarities,
|
||||
);
|
||||
},
|
||||
child: GradeValueWidget(GradeValue(index + 1, "", "", 0),
|
||||
fill: true, size: 36.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
void showRenameDialog(
|
||||
{required String title,
|
||||
required String cancel,
|
||||
required String done,
|
||||
required Map<String, String> rarities,
|
||||
required String gradeIndex,
|
||||
required List<String> defaultRarities,
|
||||
required}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => StatefulBuilder(builder: (context, setS) {
|
||||
String? rr = rarities[gradeIndex];
|
||||
rr ??= '';
|
||||
|
||||
_rarityText.text = rr;
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: TextField(
|
||||
controller: _rarityText,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
label: Text(defaultRarities[int.parse(gradeIndex) - 1]),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(FeatherIcons.x),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_rarityText.clear();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
cancel,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).maybePop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
done,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
onPressed: () {
|
||||
rarities[gradeIndex] = _rarityText.text;
|
||||
|
||||
Provider.of<DatabaseProvider>(context, listen: false)
|
||||
.userStore
|
||||
.storeGradeRarities(rarities, userId: user.id!);
|
||||
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
).then((val) {
|
||||
_rarityText.clear();
|
||||
});
|
||||
}
|
||||
}
|
26
lib/ui/mobile/settings/share_theme.dart
Normal file
26
lib/ui/mobile/settings/share_theme.dart
Normal file
|
@ -0,0 +1,26 @@
|
|||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class PremiumShareTheme extends StatefulWidget {
|
||||
const PremiumShareTheme({super.key});
|
||||
|
||||
@override
|
||||
State<PremiumShareTheme> createState() => _PremiumShareThemeState();
|
||||
}
|
||||
|
||||
class _PremiumShareThemeState extends State<PremiumShareTheme>
|
||||
with TickerProviderStateMixin {
|
||||
late final SettingsProvider settingsProvider;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
settingsProvider = Provider.of<SettingsProvider>(context, listen: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Scaffold();
|
||||
}
|
||||
}
|
660
lib/ui/mobile/settings/submenu/calendar_sync.dart
Normal file
660
lib/ui/mobile/settings/submenu/calendar_sync.dart
Normal file
|
@ -0,0 +1,660 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/models/linked_account.dart';
|
||||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc/providers/third_party_provider.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_kreta_api/providers/share_provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/dot.dart';
|
||||
import 'package:refilc_mobile_ui/common/panel/panel_button.dart';
|
||||
import 'package:refilc_mobile_ui/common/splitted_panel/splitted_panel.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/widgets/custom_segmented_control.dart';
|
||||
import 'package:refilc_mobile_ui/screens/settings/settings_screen.i18n.dart';
|
||||
import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
import 'package:refilc_plus/ui/mobile/plus/upsell.dart';
|
||||
|
||||
class MenuCalendarSync extends StatelessWidget {
|
||||
const MenuCalendarSync({
|
||||
super.key,
|
||||
this.borderRadius = const BorderRadius.vertical(
|
||||
top: Radius.circular(4.0), bottom: Radius.circular(4.0)),
|
||||
});
|
||||
|
||||
final BorderRadius borderRadius;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PanelButton(
|
||||
onPressed: () async {
|
||||
// if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
// .hasScope(PremiumScopes.calendarSync)) {
|
||||
// return PlusLockedFeaturePopup.show(
|
||||
// context: context, feature: PremiumFeature.calendarSync);
|
||||
// }
|
||||
|
||||
// Navigator.of(context, rootNavigator: true).push(CupertinoPageRoute(
|
||||
// builder: (context) => const CalendarSyncScreen()));
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Figyelem!"),
|
||||
content: const Text(
|
||||
"A naptár szinkronizálás csak azután fog működni, hogy a Google elfogadja az OAuth kérelmünket, addig is szíves türelmeteket kérjük! Amint ez megtörténik, értesíteni fogunk titeket Discord-on, valamint alkalmazáson belüli hírekben is."),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text(
|
||||
"Vissza",
|
||||
style: TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text(
|
||||
"Tovább",
|
||||
style: TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
.hasScope(PremiumScopes.calendarSync)) {
|
||||
return PlusLockedFeaturePopup.show(
|
||||
context: context, feature: PremiumFeature.calendarSync);
|
||||
}
|
||||
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const CalendarSyncScreen()));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
title: Text(
|
||||
"calendar_sync".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
leading: Icon(
|
||||
FeatherIcons.calendar,
|
||||
size: 22.0,
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
trailing: Icon(
|
||||
FeatherIcons.chevronRight,
|
||||
size: 22.0,
|
||||
color: AppColors.of(context).text.withOpacity(0.95),
|
||||
),
|
||||
borderRadius: borderRadius,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CalendarSyncScreen extends StatefulWidget {
|
||||
const CalendarSyncScreen({super.key});
|
||||
|
||||
@override
|
||||
CalendarSyncScreenState createState() => CalendarSyncScreenState();
|
||||
}
|
||||
|
||||
class CalendarSyncScreenState extends State<CalendarSyncScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late SettingsProvider settingsProvider;
|
||||
late UserProvider user;
|
||||
late ShareProvider shareProvider;
|
||||
late ThirdPartyProvider thirdPartyProvider;
|
||||
|
||||
late AnimationController _hideContainersController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
shareProvider = Provider.of<ShareProvider>(context, listen: false);
|
||||
|
||||
_hideContainersController = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 200));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
settingsProvider = Provider.of<SettingsProvider>(context);
|
||||
user = Provider.of<UserProvider>(context);
|
||||
thirdPartyProvider = Provider.of<ThirdPartyProvider>(context);
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: _hideContainersController,
|
||||
builder: (context, child) => Opacity(
|
||||
opacity: 1 - _hideContainersController.value,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
leading: BackButton(color: AppColors.of(context).text),
|
||||
title: Text(
|
||||
"calendar_sync".i18n,
|
||||
style: TextStyle(color: AppColors.of(context).text),
|
||||
),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
||||
child: Column(
|
||||
children: [
|
||||
// banner
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
image: const DecorationImage(
|
||||
image: AssetImage(
|
||||
'assets/images/banner_texture.png',
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 40,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 4.0,
|
||||
spreadRadius: 0.01,
|
||||
),
|
||||
],
|
||||
),
|
||||
height: 64,
|
||||
width: 64,
|
||||
child: const Icon(
|
||||
Icons.calendar_month,
|
||||
color: Colors.black,
|
||||
size: 38.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Icon(
|
||||
Icons.sync_alt_outlined,
|
||||
color: Colors.black.withOpacity(
|
||||
thirdPartyProvider.linkedAccounts.isEmpty
|
||||
? 0.2
|
||||
: 0.5),
|
||||
size: 20.0,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 4.0,
|
||||
spreadRadius: 0.01,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Image.asset(
|
||||
'assets/icons/ic_rounded.png',
|
||||
width: 64,
|
||||
height: 64,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(
|
||||
height: 18.0,
|
||||
),
|
||||
// choose account if not logged in
|
||||
if (thirdPartyProvider.linkedAccounts.isEmpty)
|
||||
Column(
|
||||
children: [
|
||||
if (Platform.isAndroid)
|
||||
SplittedPanel(
|
||||
title: Text('choose_account'.i18n),
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
isSeparated: true,
|
||||
children: [
|
||||
PanelButton(
|
||||
onPressed: () async {
|
||||
await Provider.of<ThirdPartyProvider>(context,
|
||||
listen: false)
|
||||
.googleSignIn();
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(
|
||||
'Google',
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
leading: Image.asset(
|
||||
'assets/images/ext_logo/google.png',
|
||||
width: 24.0,
|
||||
height: 24.0,
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// const SizedBox(
|
||||
// height: 9.0,
|
||||
// ),
|
||||
if (Platform.isIOS)
|
||||
SplittedPanel(
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
isSeparated: true,
|
||||
children: [
|
||||
PanelButton(
|
||||
onPressed: null,
|
||||
title: Text(
|
||||
'Apple',
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(.55),
|
||||
decoration: TextDecoration.lineThrough,
|
||||
),
|
||||
),
|
||||
leading: Image.asset(
|
||||
'assets/images/ext_logo/apple.png',
|
||||
width: 24.0,
|
||||
height: 24.0,
|
||||
),
|
||||
trailing: Text(
|
||||
'soon'.i18n,
|
||||
style: const TextStyle(
|
||||
fontStyle: FontStyle.italic,
|
||||
fontSize: 14.0),
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(
|
||||
height: 10.0,
|
||||
),
|
||||
const Text(
|
||||
"A naptár szinkronizálás csak azután fog működni, hogy a Google elfogadja az OAuth kérelmünket, addig is szíves türelmeteket kérjük! Amint ez megtörténik, értesíteni fogunk titeket Discord-on, valamint alkalmazáson belüli hírekben is."),
|
||||
],
|
||||
),
|
||||
|
||||
// show options if logged in
|
||||
if (thirdPartyProvider.linkedAccounts.isNotEmpty)
|
||||
Column(
|
||||
children: [
|
||||
SplittedPanel(
|
||||
title: Text('your_account'.i18n),
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
children: [
|
||||
PanelButton(
|
||||
onPressed: null,
|
||||
title: Text(
|
||||
thirdPartyProvider
|
||||
.linkedAccounts.first.username,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
leading: Image.asset(
|
||||
'assets/images/ext_logo/${thirdPartyProvider.linkedAccounts.first.type == AccountType.google ? "google" : "apple"}.png',
|
||||
width: 24.0,
|
||||
height: 24.0,
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
PanelButton(
|
||||
onPressed: () async {
|
||||
await thirdPartyProvider.signOutAll();
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(
|
||||
'change_account'.i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
trailing: Icon(
|
||||
FeatherIcons.chevronRight,
|
||||
size: 22.0,
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(0.95),
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 18.0,
|
||||
),
|
||||
SplittedPanel(
|
||||
title: Text('choose_calendar'.i18n),
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: EdgeInsets.zero,
|
||||
isTransparent: true,
|
||||
children: getCalendarList(),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 18.0,
|
||||
),
|
||||
SplittedPanel(
|
||||
title: Text('room_num_location'.i18n),
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: EdgeInsets.zero,
|
||||
isTransparent: true,
|
||||
children: [
|
||||
CustomSegmentedControl(
|
||||
onChanged: (v) {
|
||||
settingsProvider.update(
|
||||
calSyncRoomLocation:
|
||||
v == 0 ? 'location' : 'description');
|
||||
},
|
||||
value: settingsProvider.calSyncRoomLocation ==
|
||||
'location'
|
||||
? 0
|
||||
: 1,
|
||||
height: 45,
|
||||
children: [
|
||||
Text(
|
||||
'location'.i18n,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 16.0,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'description'.i18n,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 16.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 18.0,
|
||||
),
|
||||
SplittedPanel(
|
||||
title: Text('options'.i18n),
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: EdgeInsets.zero,
|
||||
isTransparent: true,
|
||||
isSeparated: true,
|
||||
children: [
|
||||
SplittedPanel(
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
children: [
|
||||
PanelButton(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 14.0, right: 6.0),
|
||||
onPressed: () async {
|
||||
settingsProvider.update(
|
||||
calSyncShowExams:
|
||||
!settingsProvider.calSyncShowExams);
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(
|
||||
"show_exams".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(
|
||||
settingsProvider.calSyncShowExams
|
||||
? .95
|
||||
: .25),
|
||||
),
|
||||
),
|
||||
trailing: Switch(
|
||||
onChanged: (v) async {
|
||||
settingsProvider.update(
|
||||
calSyncShowExams: v);
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
value: settingsProvider.calSyncShowExams,
|
||||
activeColor:
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12.0),
|
||||
bottom: Radius.circular(12.0),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SplittedPanel(
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
children: [
|
||||
PanelButton(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 14.0, right: 6.0),
|
||||
onPressed: () async {
|
||||
settingsProvider.update(
|
||||
calSyncShowTeacher: !settingsProvider
|
||||
.calSyncShowTeacher);
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(
|
||||
"show_teacher".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(settingsProvider
|
||||
.calSyncShowTeacher
|
||||
? .95
|
||||
: .25),
|
||||
),
|
||||
),
|
||||
trailing: Switch(
|
||||
onChanged: (v) async {
|
||||
settingsProvider.update(
|
||||
calSyncShowTeacher: v);
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
value: settingsProvider.calSyncShowTeacher,
|
||||
activeColor:
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12.0),
|
||||
bottom: Radius.circular(12.0),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SplittedPanel(
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
children: [
|
||||
PanelButton(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 14.0, right: 6.0),
|
||||
onPressed: () async {
|
||||
settingsProvider.update(
|
||||
calSyncRenamed:
|
||||
!settingsProvider.calSyncRenamed);
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
title: Text(
|
||||
"show_renamed".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context)
|
||||
.text
|
||||
.withOpacity(
|
||||
settingsProvider.calSyncRenamed
|
||||
? .95
|
||||
: .25),
|
||||
),
|
||||
),
|
||||
trailing: Switch(
|
||||
onChanged: (v) async {
|
||||
settingsProvider.update(
|
||||
calSyncRenamed: v);
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
value: settingsProvider.calSyncRenamed,
|
||||
activeColor:
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12.0),
|
||||
bottom: Radius.circular(12.0),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getCalendarList() {
|
||||
// List<Widget> widgets = thirdPartyProvider.googleCalendars
|
||||
// .map(
|
||||
// (e) => Container(
|
||||
// margin: const EdgeInsets.only(bottom: 3.0),
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border.all(
|
||||
// color: Theme.of(context).colorScheme.primary.withOpacity(.25),
|
||||
// width: 1.0,
|
||||
// ),
|
||||
// borderRadius: BorderRadius.circular(12.0),
|
||||
// ),
|
||||
// child: PanelButton(
|
||||
// onPressed: () async {
|
||||
// print((e.backgroundColor ?? '#000000').replaceAll('#', '0x'));
|
||||
// setState(() {});
|
||||
// },
|
||||
// title: Text(
|
||||
// e.summary ?? 'no_title'.i18n,
|
||||
// style: TextStyle(
|
||||
// color: AppColors.of(context).text.withOpacity(.95),
|
||||
// ),
|
||||
// ),
|
||||
// leading: Dot(
|
||||
// color: colorFromHex(
|
||||
// e.backgroundColor ?? '#000',
|
||||
// ) ??
|
||||
// Colors.black,
|
||||
// ),
|
||||
// borderRadius: const BorderRadius.vertical(
|
||||
// top: Radius.circular(12),
|
||||
// bottom: Radius.circular(12),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// .toList();
|
||||
|
||||
List<Widget> widgets = [];
|
||||
|
||||
widgets.add(
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 3.0),
|
||||
decoration: BoxDecoration(
|
||||
// border: Border.all(
|
||||
// color: Theme.of(context).colorScheme.primary.withOpacity(.25),
|
||||
// width: 1.0,
|
||||
// ),
|
||||
color: AppColors.of(context).highlight,
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
),
|
||||
child: PanelButton(
|
||||
onPressed: null,
|
||||
// onPressed: () async {
|
||||
// // thirdPartyProvider.pushTimetable(context, timetable);
|
||||
// setState(() {});
|
||||
// },
|
||||
title: Text(
|
||||
'reFilc - Órarend',
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
// leading: Icon(
|
||||
// FeatherIcons.plus,
|
||||
// size: 20.0,
|
||||
// color: AppColors.of(context).text.withOpacity(0.75),
|
||||
// ),
|
||||
leading: Dot(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return widgets;
|
||||
}
|
||||
}
|
363
lib/ui/mobile/settings/submenu/grade_exporting.dart
Normal file
363
lib/ui/mobile/settings/submenu/grade_exporting.dart
Normal file
|
@ -0,0 +1,363 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc/providers/third_party_provider.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_kreta_api/models/grade.dart';
|
||||
import 'package:refilc_kreta_api/providers/grade_provider.dart';
|
||||
import 'package:refilc_kreta_api/providers/share_provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/dot.dart';
|
||||
import 'package:refilc_mobile_ui/common/panel/panel_button.dart';
|
||||
import 'package:refilc_mobile_ui/common/splitted_panel/splitted_panel.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:refilc_mobile_ui/screens/settings/settings_screen.i18n.dart';
|
||||
import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
import 'package:refilc_plus/ui/mobile/plus/upsell.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:refilc_mobile_ui/common/chips/new_chip.dart';
|
||||
|
||||
class MenuGradeExporting extends StatelessWidget {
|
||||
const MenuGradeExporting({
|
||||
super.key,
|
||||
this.borderRadius = const BorderRadius.vertical(
|
||||
top: Radius.circular(4.0), bottom: Radius.circular(4.0)),
|
||||
});
|
||||
|
||||
final BorderRadius borderRadius;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PanelButton(
|
||||
onPressed: () async {
|
||||
// if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
// .hasScope(PremiumScopes.calendarSync)) {
|
||||
// return PlusLockedFeaturePopup.show(
|
||||
// context: context, feature: PremiumFeature.calendarSync);
|
||||
// }
|
||||
|
||||
// Navigator.of(context, rootNavigator: true).push(CupertinoPageRoute(
|
||||
// builder: (context) => const CalendarSyncScreen()));
|
||||
// showDialog(
|
||||
// context: context,
|
||||
// builder: (context) => AlertDialog(
|
||||
// title: const Text("Figyelem!"),
|
||||
// content: const Text(
|
||||
// "Az exportált jegyek jelenleg még nem megtekinthetők a reFilc-ben, csak te magad tudod átnézni őket JSON formátumban. A jövőben ez a funkció bővülni fog, és a jegyeket meg is tekintheted majd a reFilc felületén."),
|
||||
// actions: [
|
||||
// // TextButton(
|
||||
// // child: const Text(
|
||||
// // "Vissza",
|
||||
// // style: TextStyle(fontWeight: FontWeight.w500),
|
||||
// // ),
|
||||
// // onPressed: () {
|
||||
// // Navigator.of(context).pop();
|
||||
// // },
|
||||
// // ),
|
||||
// TextButton(
|
||||
// child: const Text(
|
||||
// "Tovább",
|
||||
// style: TextStyle(fontWeight: FontWeight.w500),
|
||||
// ),
|
||||
// onPressed: () {
|
||||
// Navigator.of(context).pop();
|
||||
|
||||
Provider.of<SettingsProvider>(context, listen: false).update(
|
||||
unseenNewFeatures: List.from(
|
||||
Provider.of<SettingsProvider>(context, listen: false)
|
||||
.unseenNewFeatures
|
||||
..remove('grade_exporting'),
|
||||
),
|
||||
);
|
||||
// Provider.of<SettingsProvider>(context, listen: false).update(
|
||||
// unseenNewFeatures: ['grade_exporting'],
|
||||
// );
|
||||
|
||||
if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
.hasScope(PremiumScopes.gradeExporting)) {
|
||||
return PlusLockedFeaturePopup.show(
|
||||
context: context, feature: PremiumFeature.gradeExporting);
|
||||
}
|
||||
|
||||
Navigator.of(context, rootNavigator: true).push(CupertinoPageRoute(
|
||||
builder: (context) => const GradeExportingScreen()));
|
||||
// },
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
},
|
||||
title: Text(
|
||||
"grade_exporting".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
leading: Icon(
|
||||
Icons.toll_rounded,
|
||||
size: 22.0,
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (Provider.of<SettingsProvider>(context)
|
||||
.unseenNewFeatures
|
||||
.contains('grade_exporting'))
|
||||
const NewChip(),
|
||||
Icon(
|
||||
FeatherIcons.chevronRight,
|
||||
size: 22.0,
|
||||
color: AppColors.of(context).text.withOpacity(0.95),
|
||||
)
|
||||
],
|
||||
),
|
||||
borderRadius: borderRadius,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GradeExportingScreen extends StatefulWidget {
|
||||
const GradeExportingScreen({super.key});
|
||||
|
||||
@override
|
||||
CalendarSyncScreenState createState() => CalendarSyncScreenState();
|
||||
}
|
||||
|
||||
class CalendarSyncScreenState extends State<GradeExportingScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late SettingsProvider settingsProvider;
|
||||
late UserProvider user;
|
||||
late ShareProvider shareProvider;
|
||||
late ThirdPartyProvider thirdPartyProvider;
|
||||
|
||||
late AnimationController _hideContainersController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
shareProvider = Provider.of<ShareProvider>(context, listen: false);
|
||||
|
||||
_hideContainersController = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 200));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
settingsProvider = Provider.of<SettingsProvider>(context);
|
||||
user = Provider.of<UserProvider>(context);
|
||||
thirdPartyProvider = Provider.of<ThirdPartyProvider>(context);
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: _hideContainersController,
|
||||
builder: (context, child) => Opacity(
|
||||
opacity: 1 - _hideContainersController.value,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
leading: BackButton(color: AppColors.of(context).text),
|
||||
title: Text(
|
||||
"grade_exporting".i18n,
|
||||
style: TextStyle(color: AppColors.of(context).text),
|
||||
),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
||||
child: Column(
|
||||
children: [
|
||||
// choose export method
|
||||
Column(
|
||||
children: [
|
||||
SplittedPanel(
|
||||
title: Text('export_method'.i18n),
|
||||
padding: EdgeInsets.zero,
|
||||
cardPadding: const EdgeInsets.all(4.0),
|
||||
isSeparated: true,
|
||||
children: [
|
||||
PanelButton(
|
||||
onPressed: () async {
|
||||
// get all grades
|
||||
List<Grade> grades = Provider.of<GradeProvider>(
|
||||
context,
|
||||
listen: false)
|
||||
.grades;
|
||||
|
||||
// gmake a list of grades in json format
|
||||
List<Map<dynamic, dynamic>> gradesList = [
|
||||
for (Grade grade in grades)
|
||||
// {
|
||||
// '"subject"': '"${grade.subject.name}"',
|
||||
// '"value"': grade.value.value,
|
||||
// '"value_name"':
|
||||
// '"${grade.value.valueName}"',
|
||||
// '"date"':
|
||||
// '"${grade.date.toIso8601String()}"',
|
||||
// '"weight"': grade.value.weight,
|
||||
// '"type"': '"${grade.type.name}"',
|
||||
// '"description"': '"${grade.description}"',
|
||||
// '"teacher"': '"${grade.teacher.name}"',
|
||||
// }
|
||||
grade.json ?? {},
|
||||
];
|
||||
|
||||
// convert list to json file
|
||||
final directory = await getTemporaryDirectory();
|
||||
|
||||
File file = File('${directory.path}/grades.json');
|
||||
file.writeAsStringSync(
|
||||
jsonEncode(gradesList),
|
||||
);
|
||||
|
||||
// convert json to bytes
|
||||
final jsonBytes = file.readAsBytesSync();
|
||||
|
||||
// get current study year
|
||||
final now = DateTime.now();
|
||||
String studyYearStr = '';
|
||||
if (now.month <= 8) {
|
||||
studyYearStr = '${now.year - 1}_${now.year}';
|
||||
} else {
|
||||
studyYearStr = '${now.year}_${now.year + 1}';
|
||||
}
|
||||
|
||||
// open the share popup with the json file
|
||||
Share.shareXFiles(
|
||||
[
|
||||
XFile.fromData(
|
||||
jsonBytes,
|
||||
name: 'refilc_grades_$studyYearStr',
|
||||
mimeType: 'application/json',
|
||||
),
|
||||
],
|
||||
subject:
|
||||
'reFilc Jegyek - ${studyYearStr.replaceAll('_', '/')}',
|
||||
);
|
||||
},
|
||||
title: Text(
|
||||
'JSON',
|
||||
style: TextStyle(
|
||||
color:
|
||||
AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
// leading: Image.asset(
|
||||
// 'assets/images/ext_logo/google.png',
|
||||
// width: 24.0,
|
||||
// height: 24.0,
|
||||
// ),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// const SizedBox(
|
||||
// height: 10.0,
|
||||
// ),
|
||||
// const Text(
|
||||
// "Az exportált jegyek jelenleg még nem megtekinthetők a reFilc-ben, csak te magad tudod átnézni őket JSON formátumban. A jövőben ez a funkció bővülni fog, és a jegyeket meg is tekintheted majd a reFilc felületén."),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> getCalendarList() {
|
||||
// List<Widget> widgets = thirdPartyProvider.googleCalendars
|
||||
// .map(
|
||||
// (e) => Container(
|
||||
// margin: const EdgeInsets.only(bottom: 3.0),
|
||||
// decoration: BoxDecoration(
|
||||
// border: Border.all(
|
||||
// color: Theme.of(context).colorScheme.primary.withOpacity(.25),
|
||||
// width: 1.0,
|
||||
// ),
|
||||
// borderRadius: BorderRadius.circular(12.0),
|
||||
// ),
|
||||
// child: PanelButton(
|
||||
// onPressed: () async {
|
||||
// print((e.backgroundColor ?? '#000000').replaceAll('#', '0x'));
|
||||
// setState(() {});
|
||||
// },
|
||||
// title: Text(
|
||||
// e.summary ?? 'no_title'.i18n,
|
||||
// style: TextStyle(
|
||||
// color: AppColors.of(context).text.withOpacity(.95),
|
||||
// ),
|
||||
// ),
|
||||
// leading: Dot(
|
||||
// color: colorFromHex(
|
||||
// e.backgroundColor ?? '#000',
|
||||
// ) ??
|
||||
// Colors.black,
|
||||
// ),
|
||||
// borderRadius: const BorderRadius.vertical(
|
||||
// top: Radius.circular(12),
|
||||
// bottom: Radius.circular(12),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// .toList();
|
||||
|
||||
List<Widget> widgets = [];
|
||||
|
||||
widgets.add(
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 3.0),
|
||||
decoration: BoxDecoration(
|
||||
// border: Border.all(
|
||||
// color: Theme.of(context).colorScheme.primary.withOpacity(.25),
|
||||
// width: 1.0,
|
||||
// ),
|
||||
color: AppColors.of(context).highlight,
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
),
|
||||
child: PanelButton(
|
||||
onPressed: null,
|
||||
// onPressed: () async {
|
||||
// // thirdPartyProvider.pushTimetable(context, timetable);
|
||||
// setState(() {});
|
||||
// },
|
||||
title: Text(
|
||||
'reFilc - Órarend',
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
// leading: Icon(
|
||||
// FeatherIcons.plus,
|
||||
// size: 20.0,
|
||||
// color: AppColors.of(context).text.withOpacity(0.75),
|
||||
// ),
|
||||
leading: Dot(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return widgets;
|
||||
}
|
||||
}
|
157
lib/ui/mobile/settings/welcome_message.dart
Normal file
157
lib/ui/mobile/settings/welcome_message.dart
Normal file
|
@ -0,0 +1,157 @@
|
|||
import 'package:refilc/api/providers/user_provider.dart';
|
||||
import 'package:refilc/models/settings.dart';
|
||||
import 'package:refilc/theme/colors/colors.dart';
|
||||
import 'package:refilc_mobile_ui/common/panel/panel_button.dart';
|
||||
import 'package:refilc_plus/models/premium_scopes.dart';
|
||||
import 'package:refilc_plus/providers/plus_provider.dart';
|
||||
import 'package:refilc_plus/ui/mobile/plus/upsell.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:refilc_mobile_ui/screens/settings/settings_screen.i18n.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:i18n_extension/i18n_extension.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class WelcomeMessagePanelButton extends StatelessWidget {
|
||||
late SettingsProvider settingsProvider;
|
||||
late UserProvider user;
|
||||
|
||||
WelcomeMessagePanelButton(this.settingsProvider, this.user, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String finalName = ((user.nickname ?? '') != ''
|
||||
? user.nickname
|
||||
: (user.displayName ?? '') != ''
|
||||
? user.displayName
|
||||
: 'János') ??
|
||||
'János';
|
||||
|
||||
return PanelButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => WelcomeMessageEditor(settingsProvider));
|
||||
},
|
||||
title: Text(
|
||||
"welcome_msg".i18n,
|
||||
style: TextStyle(
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
),
|
||||
leading: Icon(
|
||||
FeatherIcons.smile,
|
||||
size: 22.0,
|
||||
color: AppColors.of(context).text.withOpacity(.95),
|
||||
),
|
||||
trailing: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 100),
|
||||
child: Text(
|
||||
settingsProvider.welcomeMessage.replaceAll(' ', '') != ''
|
||||
? localizeFill(
|
||||
settingsProvider.welcomeMessage,
|
||||
[finalName],
|
||||
)
|
||||
: 'default'.i18n,
|
||||
style: const TextStyle(fontSize: 14.0),
|
||||
textAlign: TextAlign.end,
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class WelcomeMessageEditor extends StatefulWidget {
|
||||
late SettingsProvider settingsProvider;
|
||||
|
||||
WelcomeMessageEditor(this.settingsProvider, {super.key});
|
||||
|
||||
@override
|
||||
State<WelcomeMessageEditor> createState() => _WelcomeMessageEditorState();
|
||||
}
|
||||
|
||||
class _WelcomeMessageEditorState extends State<WelcomeMessageEditor> {
|
||||
final _welcomeMsg = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_welcomeMsg.text =
|
||||
widget.settingsProvider.welcomeMessage.replaceAll('%s', '%name%');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text("edit_welcome_msg".i18n),
|
||||
content: TextField(
|
||||
controller: _welcomeMsg,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
label: Text('welcome_msg'.i18n),
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(FeatherIcons.x),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_welcomeMsg.text = "";
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
"cancel".i18n,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).maybePop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
"done".i18n,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
onPressed: () {
|
||||
// var trimmed = _welcomeMsg.text.trim();
|
||||
|
||||
// var defLen = trimmed.length;
|
||||
// var replacedLen = trimmed.replaceAll('%s', '').length;
|
||||
|
||||
// if (defLen - 2 > replacedLen) {
|
||||
// print('fuck yourself rn');
|
||||
// }
|
||||
var finalText = _welcomeMsg.text
|
||||
.trim()
|
||||
.replaceFirst('%name%', '\$s')
|
||||
.replaceFirst('%user%', '\$s')
|
||||
.replaceFirst('%username%', '\$s')
|
||||
.replaceFirst('%me%', '\$s')
|
||||
.replaceFirst('%profile%', '\$s')
|
||||
.replaceAll('%', '')
|
||||
.replaceFirst('\$s', '%s');
|
||||
// .replaceAll('\$s', 's');
|
||||
|
||||
if (!Provider.of<PlusProvider>(context, listen: false)
|
||||
.hasScope(PremiumScopes.welcomeMessage) &&
|
||||
finalText.replaceAll(' ', '') != '') {
|
||||
PlusLockedFeaturePopup.show(
|
||||
context: context, feature: PremiumFeature.welcomeMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
widget.settingsProvider
|
||||
.update(welcomeMessage: finalText, store: true);
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue