fixed most reported bugs

This commit is contained in:
Kima
2023-05-30 19:27:16 +02:00
parent f5682e9137
commit d1507f5eae
23 changed files with 1570 additions and 1124 deletions

View File

@@ -29,16 +29,18 @@ import 'package:flutter_expandable_fab/flutter_expandable_fab.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart';
import 'grades_page.i18n.dart';
// import 'package:filcnaplo_premium/ui/mobile/goalplanner/new_goal.dart';
// import 'package:filcnaplo_premium/ui/mobile/goal_planner/new_goal.dart';
class GradeSubjectView extends StatefulWidget {
const GradeSubjectView(this.subject, {Key? key, this.groupAverage = 0.0}) : super(key: key);
const GradeSubjectView(this.subject, {Key? key, this.groupAverage = 0.0})
: super(key: key);
final Subject subject;
final double groupAverage;
void push(BuildContext context, {bool root = false}) {
Navigator.of(context, rootNavigator: root).push(CupertinoPageRoute(builder: (context) => this));
Navigator.of(context, rootNavigator: root)
.push(CupertinoPageRoute(builder: (context) => this));
}
@override
@@ -73,7 +75,8 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
final gradeDates = subjectGrades.map((e) => e.date.millisecondsSinceEpoch);
final maxGradeDate = gradeDates.fold(0, max);
final minGradeDate = gradeDates.fold(0, min);
if (maxGradeDate - minGradeDate < const Duration(days: 5).inMilliseconds) return false; // naplo/#78
if (maxGradeDate - minGradeDate < const Duration(days: 5).inMilliseconds)
return false; // naplo/#78
return subjectGrades.where((e) => e.type == GradeType.midYear).length > 1;
}
@@ -139,7 +142,8 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
),
);
tiles.add(Padding(padding: EdgeInsets.only(bottom: !gradeCalcMode ? 24.0 : 250.0)));
tiles.add(Padding(
padding: EdgeInsets.only(bottom: !gradeCalcMode ? 24.0 : 250.0)));
gradeTiles = List.castFrom(tiles);
}
@@ -152,7 +156,10 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
average = AverageHelper.averageEvals(subjectGrades);
final prevAvg = subjectGrades.isNotEmpty
? AverageHelper.averageEvals(subjectGrades
.where((e) => e.date.isBefore(subjectGrades.reduce((v, e) => e.date.isAfter(v.date) ? e : v).date.subtract(const Duration(days: 30))))
.where((e) => e.date.isBefore(subjectGrades
.reduce((v, e) => e.date.isAfter(v.date) ? e : v)
.date
.subtract(const Duration(days: 30))))
.toList())
: 0.0;
@@ -163,12 +170,14 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("annual_average".i18n),
if (average != prevAvg) TrendDisplay(current: average, previous: prevAvg),
if (average != prevAvg)
TrendDisplay(current: average, previous: prevAvg),
],
),
child: Container(
padding: const EdgeInsets.only(top: 16.0, right: 12.0),
child: GradeGraph(subjectGrades, dayThreshold: 5, classAvg: widget.groupAverage),
child: GradeGraph(subjectGrades,
dayThreshold: 5, classAvg: widget.groupAverage),
),
),
);
@@ -176,7 +185,9 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
if (!gradeCalcMode) {
buildTiles(subjectGrades);
} else {
List<Grade> ghostGrades = calculatorProvider.ghosts.where((e) => e.subject == widget.subject).toList();
List<Grade> ghostGrades = calculatorProvider.ghosts
.where((e) => e.subject == widget.subject)
.toList();
buildTiles(ghostGrades);
}
@@ -184,7 +195,10 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
key: _scaffoldKey,
floatingActionButtonLocation: ExpandableFab.location,
floatingActionButton: Visibility(
visible: !gradeCalcMode && subjectGrades.where((e) => e.type == GradeType.midYear).isNotEmpty,
visible: !gradeCalcMode &&
subjectGrades
.where((e) => e.type == GradeType.midYear)
.isNotEmpty,
child: ExpandableFab(
backgroundColor: Theme.of(context).colorScheme.secondary,
type: ExpandableFabType.up,
@@ -204,14 +218,19 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
child: const Icon(FeatherIcons.flag, size: 20.0),
backgroundColor: Theme.of(context).colorScheme.secondary,
onPressed: () {
if (!Provider.of<PremiumProvider>(context, listen: false).hasScope(PremiumScopes.goalPlanner)) {
PremiumLockedFeatureUpsell.show(context: context, feature: PremiumFeature.goalplanner);
if (!Provider.of<PremiumProvider>(context, listen: false)
.hasScope(PremiumScopes.goalPlanner)) {
PremiumLockedFeatureUpsell.show(
context: context, feature: PremiumFeature.goalplanner);
return;
}
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Hamarosan...")));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Hamarosan...")));
// Navigator.of(context).push(CupertinoPageRoute(builder: (context) => PremiumGoalplannerNewGoalScreen(subject: widget.subject)));
//Navigator.of(context).push(CupertinoPageRoute(
//builder: (context) => PremiumGoalplannerNewGoalScreen(
// subject: widget.subject)));
},
),
],
@@ -230,12 +249,17 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
},
navBarItems: [
const SizedBox(width: 6.0),
if (widget.groupAverage != 0) Center(child: AverageDisplay(average: widget.groupAverage, border: true)),
if (widget.groupAverage != 0)
Center(
child: AverageDisplay(
average: widget.groupAverage, border: true)),
const SizedBox(width: 6.0),
if (average != 0) Center(child: AverageDisplay(average: average)),
if (average != 0)
Center(child: AverageDisplay(average: average)),
const SizedBox(width: 12.0),
],
icon: SubjectIcon.resolveVariant(subject: widget.subject, context: context),
icon: SubjectIcon.resolveVariant(
subject: widget.subject, context: context),
scrollController: _scrollController,
title: widget.subject.renamedTo ?? widget.subject.name.capital(),
italic: widget.subject.isRenamed,
@@ -255,13 +279,15 @@ class _GradeSubjectViewState extends State<GradeSubjectView> {
void gradeCalc(BuildContext context) {
// Scroll to the top of the page
_scrollController.animateTo(75, duration: const Duration(milliseconds: 500), curve: Curves.ease);
_scrollController.animateTo(75,
duration: const Duration(milliseconds: 500), curve: Curves.ease);
calculatorProvider.clear();
calculatorProvider.addAllGrades(gradeProvider.grades);
_sheetController = _scaffoldKey.currentState?.showBottomSheet(
(context) => RoundedBottomSheet(child: GradeCalculator(widget.subject), borderRadius: 14.0),
(context) => RoundedBottomSheet(
child: GradeCalculator(widget.subject), borderRadius: 14.0),
backgroundColor: const Color(0x00000000),
elevation: 12.0,
);