fixed grades page ui in summary

This commit is contained in:
kima 2023-06-17 20:04:11 +02:00
parent 5c39865d40
commit 3579c4e821
7 changed files with 283 additions and 171 deletions

View File

@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin.h> #include <dynamic_color/dynamic_color_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_acrylic/flutter_acrylic_plugin.h> #include <flutter_acrylic/flutter_acrylic_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h> #include <url_launcher_linux/url_launcher_plugin.h>
@ -14,6 +15,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar = g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar); dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) flutter_acrylic_registrar = g_autoptr(FlPluginRegistrar) flutter_acrylic_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAcrylicPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAcrylicPlugin");
flutter_acrylic_plugin_register_with_registrar(flutter_acrylic_registrar); flutter_acrylic_plugin_register_with_registrar(flutter_acrylic_registrar);

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color dynamic_color
file_selector_linux
flutter_acrylic flutter_acrylic
url_launcher_linux url_launcher_linux
) )

View File

@ -7,6 +7,7 @@ import Foundation
import connectivity_plus import connectivity_plus
import dynamic_color import dynamic_color
import file_selector_macos
import flutter_local_notifications import flutter_local_notifications
import macos_window_utils import macos_window_utils
import package_info_plus import package_info_plus
@ -18,6 +19,7 @@ import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin")) DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
MacOSWindowUtilsPlugin.register(with: registry.registrar(forPlugin: "MacOSWindowUtilsPlugin")) MacOSWindowUtilsPlugin.register(with: registry.registrar(forPlugin: "MacOSWindowUtilsPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))

View File

@ -23,7 +23,6 @@ class Empty extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// make the face randomness a bit more constant (to avoid strokes)
int index = Random(DateTime.now().minute).nextInt(faces.length); int index = Random(DateTime.now().minute).nextInt(faces.length);
return Center( return Center(
@ -32,9 +31,19 @@ class Empty extends StatelessWidget {
child: Text.rich( child: Text.rich(
TextSpan( TextSpan(
text: faces[index], text: faces[index],
style: TextStyle(fontSize: 32.0, fontWeight: FontWeight.w500, color: AppColors.of(context).text.withOpacity(.75)), style: TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.w500,
color: AppColors.of(context).text.withOpacity(.75)),
children: subtitle != null children: subtitle != null
? [TextSpan(text: "\n" + subtitle!, style: TextStyle(fontSize: 18.0, height: 2.0, color: AppColors.of(context).text.withOpacity(.5)))] ? [
TextSpan(
text: "\n" + subtitle!,
style: TextStyle(
fontSize: 18.0,
height: 2.0,
color: AppColors.of(context).text.withOpacity(.5)))
]
: [], : [],
), ),
textAlign: TextAlign.center, textAlign: TextAlign.center,

View File

@ -13,6 +13,7 @@ import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:i18n_extension/i18n_widget.dart'; import 'package:i18n_extension/i18n_widget.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:wtf_sliding_sheet/wtf_sliding_sheet.dart';
import 'live_card.i18n.dart'; import 'live_card.i18n.dart';
class LiveCard extends StatefulWidget { class LiveCard extends StatefulWidget {
@ -66,13 +67,30 @@ class _LiveCardState extends State<LiveCard> {
color: Theme.of(context).textTheme.bodyMedium?.color, color: Theme.of(context).textTheme.bodyMedium?.color,
), ),
), ),
onTap: () => Navigator.of(context).push( onTap: () {
MaterialPageRoute( showSlidingBottomSheet(
builder: (BuildContext context) => const SummaryScreen( context,
currentPage: 'grades', useRootNavigator: true,
builder: (context) => SlidingSheetDialog(
color: Theme.of(context).scaffoldBackgroundColor,
duration: const Duration(milliseconds: 400),
scrollSpec: const ScrollSpec.bouncingScroll(),
snapSpec: const SnapSpec(
snap: true,
snappings: [1.0],
positioning: SnapPositioning.relativeToSheetHeight,
),
cornerRadius: 16,
cornerRadiusOnFullscreen: 0,
builder: (context, state) => Material(
color: Theme.of(context).scaffoldBackgroundColor,
child: const SummaryScreen(
currentPage: 'grades',
),
),
), ),
), );
), },
); );
break; break;
case LiveCardState.morning: case LiveCardState.morning:

View File

@ -3,18 +3,29 @@ import 'dart:math';
import 'package:filcnaplo/api/providers/user_provider.dart'; import 'package:filcnaplo/api/providers/user_provider.dart';
import 'package:filcnaplo/helpers/average_helper.dart'; import 'package:filcnaplo/helpers/average_helper.dart';
import 'package:filcnaplo/models/settings.dart'; import 'package:filcnaplo/models/settings.dart';
import 'package:filcnaplo/theme/colors/colors.dart';
import 'package:filcnaplo/ui/widgets/grade/grade_tile.dart'; import 'package:filcnaplo/ui/widgets/grade/grade_tile.dart';
import 'package:filcnaplo/utils/format.dart'; import 'package:filcnaplo/utils/format.dart';
import 'package:filcnaplo_kreta_api/models/grade.dart'; import 'package:filcnaplo_kreta_api/models/grade.dart';
import 'package:filcnaplo_kreta_api/models/subject.dart'; import 'package:filcnaplo_kreta_api/models/subject.dart';
import 'package:filcnaplo_kreta_api/providers/grade_provider.dart'; import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
import 'package:filcnaplo_mobile_ui/common/empty.dart'; import 'package:filcnaplo_mobile_ui/screens/summary/summary_screen.i18n.dart';
import 'package:filcnaplo_mobile_ui/pages/grades/grades_page.i18n.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
List<String> faces = [
"(·.·)",
"(≥o≤)",
"(·_·)",
"(˚Δ˚)b",
"(^-^*)",
"(='X'=)",
"(>_<)",
"(;-;)",
"\\(^Д^)/",
"\\(o_o)/",
];
class GradesBody extends StatefulWidget { class GradesBody extends StatefulWidget {
const GradesBody({Key? key}) : super(key: key); const GradesBody({Key? key}) : super(key: key);
@ -49,6 +60,7 @@ class _GradesBodyState extends State<GradesBody> {
void initState() { void initState() {
super.initState(); super.initState();
gradeProvider = Provider.of<GradeProvider>(context, listen: false);
settings = Provider.of<SettingsProvider>(context, listen: false); settings = Provider.of<SettingsProvider>(context, listen: false);
} }
@ -62,41 +74,65 @@ class _GradesBodyState extends State<GradesBody> {
Map<Subject, double> subjectAvgs = {}; Map<Subject, double> subjectAvgs = {};
tiles.addAll(subjects.map((subject) { for (Subject subject in subjects) {
List<Grade> subjectGrades = getSubjectGrades(subject); List<Grade> subjectGrades = getSubjectGrades(subject);
double avg = AverageHelper.averageEvals(subjectGrades); double avg = AverageHelper.averageEvals(subjectGrades);
if (avg != 0) subjectAvgs[subject] = avg; if (avg != 0) subjectAvgs[subject] = avg;
if (avg.round() == filter) { Widget widget = Row(
return Row( children: [
children: [ GradeValueWidget(
GradeValueWidget( GradeValue(avg.round(), '', '', 100),
GradeValue(avg.round(), '', '', 100), fill: true,
fill: true, size: 28.0,
size: 22.0, ),
const SizedBox(width: 8),
Text(
subject.renamedTo ?? subject.name.capital(),
maxLines: 2,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.white.withOpacity(0.98),
fontStyle: settings.renamedSubjectsItalics && subject.isRenamed
? FontStyle.italic
: null,
), ),
Text( )
subject.renamedTo ?? subject.name.capital(), ],
maxLines: 2, );
style: TextStyle(
fontWeight: FontWeight.w600, if (avg.round() == filter) {
fontSize: 18.0, tiles.add(widget);
color: AppColors.of(context).text,
fontStyle: settings.renamedSubjectsItalics && subject.isRenamed
? FontStyle.italic
: null,
),
)
],
);
} else {
return Container();
} }
})); }
if (tiles.isEmpty) { if (tiles.isEmpty) {
tiles.insert(0, Empty(subtitle: "empty".i18n)); int index = Random(DateTime.now().minute).nextInt(faces.length);
Widget faceWidget = Center(
child: Text.rich(
TextSpan(
text: faces[index],
style: const TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.w500,
color: Colors.white,
),
children: [
TextSpan(
text: "\nno_grades".i18n,
style: TextStyle(
fontSize: 18.0,
height: 2.0,
color: Colors.white.withOpacity(0.5)),
),
],
),
textAlign: TextAlign.center,
),
);
tiles.insert(0, faceWidget);
} }
subjectAvg = subjectAvgs.isNotEmpty subjectAvg = subjectAvgs.isNotEmpty
@ -106,17 +142,15 @@ class _GradesBodyState extends State<GradesBody> {
if (filter == 5) { if (filter == 5) {
subjectTiles5 = List.castFrom(tiles); subjectTiles5 = List.castFrom(tiles);
if (subjectTiles5.length > 5) { if (subjectTiles5.length > 4) {
subjectTiles5.length = 5; subjectTiles5.length = 4;
} }
} } else if (filter == 3) {
if (filter == 3) {
subjectTiles3 = List.castFrom(tiles); subjectTiles3 = List.castFrom(tiles);
if (subjectTiles3.length > 3) { if (subjectTiles3.length > 3) {
subjectTiles3.length = 3; subjectTiles3.length = 3;
} }
} } else if (filter == 1) {
if (filter == 1) {
subjectTiles1 = List.castFrom(tiles); subjectTiles1 = List.castFrom(tiles);
if (subjectTiles1.length > 2) { if (subjectTiles1.length > 2) {
subjectTiles1.length = 2; subjectTiles1.length = 2;
@ -124,6 +158,12 @@ class _GradesBodyState extends State<GradesBody> {
} }
} }
void getGrades() {
generateTiles(filter: 5);
generateTiles(filter: 3);
generateTiles(filter: 1);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
user = Provider.of<UserProvider>(context); user = Provider.of<UserProvider>(context);
@ -136,152 +176,176 @@ class _GradesBodyState extends State<GradesBody> {
firstName = "János"; firstName = "János";
} }
generateTiles(filter: 5); getGrades();
generateTiles(filter: 3);
generateTiles(filter: 1);
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
'Jó éved volt, $firstName!', 'Jó éved volt, $firstName!',
style: TextStyle( textAlign: TextAlign.left,
fontWeight: FontWeight.bold, style: const TextStyle(
fontSize: 24.0, fontWeight: FontWeight.w900,
color: Theme.of(context).textTheme.bodyMedium?.color, fontSize: 26.0,
color: Colors.white,
), ),
), ),
Text( const Text(
'Nézzük a jegyeidet... 📖', 'Nézzük a jegyeidet... 📖',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 20.0, fontSize: 22.0,
color: Theme.of(context).textTheme.bodyMedium?.color, color: Colors.white,
), ),
), ),
const SizedBox(height: 20.0), const SizedBox(height: 12.0),
ListView.builder( SizedBox(
padding: EdgeInsets.zero, height: ((100 * subjectTiles5.length) /
physics: const BouncingScrollPhysics(), (subjectTiles5[0].runtimeType == Row ? 1.95 : 1.2))
itemCount: max(subjectTiles5.length, 1), .toDouble(),
itemBuilder: (context, index) { child: ListView.builder(
if (subjectTiles5.isNotEmpty) { padding: const EdgeInsets.only(left: 5),
EdgeInsetsGeometry panelPadding = physics: const BouncingScrollPhysics(),
const EdgeInsets.symmetric(horizontal: 24.0); itemCount: max(subjectTiles5.length, 1),
itemBuilder: (context, index) {
if (subjectTiles5.isNotEmpty) {
EdgeInsetsGeometry panelPadding =
const EdgeInsets.symmetric(horizontal: 24.0);
if (subjectTiles5[index].runtimeType == Row) { if (subjectTiles5[index].runtimeType == Row) {
return subjectTiles5[index]; return Padding(
padding: const EdgeInsets.only(top: 8),
child: subjectTiles5[index]);
} else {
return Padding(
padding: panelPadding, child: subjectTiles5[index]);
}
} else { } else {
return Padding( return Container();
padding: panelPadding, child: subjectTiles5[index]);
} }
} else { },
return Container(); ),
}
},
), ),
const SizedBox(height: 20.0), const SizedBox(height: 12.0),
Text( const Text(
'Próba teszi a mestert! 🔃', 'Próba teszi a mestert! 🔃',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 20.0, fontSize: 22.0,
color: Theme.of(context).textTheme.bodyMedium?.color, color: Colors.white,
), ),
), ),
const SizedBox(height: 20.0), const SizedBox(height: 12.0),
ListView.builder( SizedBox(
padding: EdgeInsets.zero, height: ((100 * subjectTiles3.length) /
physics: const BouncingScrollPhysics(), (subjectTiles3[0].runtimeType == Row ? 1.95 : 1.2))
itemCount: max(subjectTiles3.length, 1), .toDouble(),
itemBuilder: (context, index) { child: ListView.builder(
if (subjectTiles3.isNotEmpty) { padding: const EdgeInsets.only(left: 5),
EdgeInsetsGeometry panelPadding = physics: const BouncingScrollPhysics(),
const EdgeInsets.symmetric(horizontal: 24.0); itemCount: max(subjectTiles3.length, 1),
itemBuilder: (context, index) {
if (subjectTiles3.isNotEmpty) {
EdgeInsetsGeometry panelPadding =
const EdgeInsets.symmetric(horizontal: 24.0);
if (subjectTiles3[index].runtimeType == Row) { if (subjectTiles3[index].runtimeType == Row) {
return subjectTiles3[index]; return Padding(
padding: const EdgeInsets.only(top: 8),
child: subjectTiles3[index]);
} else {
return Padding(
padding: panelPadding, child: subjectTiles3[index]);
}
} else { } else {
return Padding( return Container();
padding: panelPadding, child: subjectTiles3[index]);
} }
} else { },
return Container(); ),
}
},
), ),
const SizedBox(height: 20.0), const SizedBox(height: 12.0),
Text( const Text(
'Ajajj... 🥴', 'Ajajj... 🥴',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 20.0, fontSize: 22.0,
color: Theme.of(context).textTheme.bodyMedium?.color, color: Colors.white,
), ),
), ),
const SizedBox(height: 20.0), const SizedBox(height: 12.0),
ListView.builder( SizedBox(
padding: EdgeInsets.zero, height: ((100 * subjectTiles1.length) /
physics: const BouncingScrollPhysics(), (subjectTiles1[0].runtimeType == Row ? 1.95 : 1.2))
itemCount: max(subjectTiles1.length, 1), .toDouble(),
itemBuilder: (context, index) { child: ListView.builder(
if (subjectTiles1.isNotEmpty) { padding: const EdgeInsets.only(left: 5),
EdgeInsetsGeometry panelPadding = physics: const BouncingScrollPhysics(),
const EdgeInsets.symmetric(horizontal: 24.0); itemCount: max(subjectTiles1.length, 1),
itemBuilder: (context, index) {
if (subjectTiles1.isNotEmpty) {
EdgeInsetsGeometry panelPadding =
const EdgeInsets.symmetric(horizontal: 24.0);
if (subjectTiles1[index].runtimeType == Row) { if (subjectTiles1[index].runtimeType == Row) {
return subjectTiles1[index]; return Padding(
padding: const EdgeInsets.only(top: 8),
child: subjectTiles1[index]);
} else {
return Padding(
padding: panelPadding, child: subjectTiles1[index]);
}
} else { } else {
return Padding( return Container();
padding: panelPadding, child: subjectTiles1[index]);
} }
} else { },
return Container(); ),
}
},
), ),
const SizedBox(height: 40.0), const SizedBox(height: 40.0),
Column( Center(
mainAxisAlignment: MainAxisAlignment.center, child: Column(
crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ crossAxisAlignment: CrossAxisAlignment.center,
Text( children: [
'Év végi átlagod', const Text(
style: TextStyle( 'Év végi átlagod',
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
Container(
margin: const EdgeInsets.only(top: 4.0),
padding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
decoration: BoxDecoration(
color: gradeColor(context: context, value: subjectAvg)
.withOpacity(.2),
border: Border.all(
color: (gradeColor(context: context, value: subjectAvg))
.withOpacity(0.0),
width: 2.0,
),
borderRadius: BorderRadius.circular(45.0),
),
child: AutoSizeText.rich(
TextSpan(
text: subjectAvg.toString(),
),
maxLines: 1,
minFontSize: 5,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: gradeColor(context: context, value: subjectAvg), fontWeight: FontWeight.bold,
fontWeight: FontWeight.w800, fontSize: 22.0,
fontSize: 32.0, color: Colors.white,
), ),
), ),
), Container(
], margin: const EdgeInsets.only(top: 10.0),
) padding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
decoration: BoxDecoration(
color: gradeColor(context: context, value: subjectAvg)
.withOpacity(.2),
border: Border.all(
color: (gradeColor(context: context, value: subjectAvg))
.withOpacity(0.0),
width: 2.0,
),
borderRadius: BorderRadius.circular(45.0),
),
child: AutoSizeText.rich(
TextSpan(
text: subjectAvg.toStringAsFixed(2),
),
maxLines: 1,
minFontSize: 5,
textAlign: TextAlign.center,
style: TextStyle(
color: gradeColor(context: context, value: subjectAvg),
fontWeight: FontWeight.w800,
fontSize: 32.0,
),
),
),
],
),
),
], ],
); );
} }

View File

@ -15,7 +15,9 @@ class SummaryScreen extends StatefulWidget {
_SummaryScreenState createState() => _SummaryScreenState(); _SummaryScreenState createState() => _SummaryScreenState();
} }
class _SummaryScreenState extends State<SummaryScreen> { class _SummaryScreenState extends State<SummaryScreen>
with SingleTickerProviderStateMixin {
late AnimationController _hideContainersController;
ConfettiController? _confettiController; ConfettiController? _confettiController;
final LinearGradient _backgroundGradient = const LinearGradient( final LinearGradient _backgroundGradient = const LinearGradient(
@ -28,6 +30,14 @@ class _SummaryScreenState extends State<SummaryScreen> {
stops: [-1.0, 1.0], stops: [-1.0, 1.0],
); );
@override
void initState() {
super.initState();
_hideContainersController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 200));
}
@override @override
void dispose() { void dispose() {
_confettiController?.dispose(); _confettiController?.dispose();
@ -37,28 +47,32 @@ class _SummaryScreenState extends State<SummaryScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return AnimatedBuilder(
body: Container( animation: _hideContainersController,
decoration: BoxDecoration(gradient: _backgroundGradient), builder: (context, child) => Opacity(
opacity: 1 - _hideContainersController.value,
child: Container( child: Container(
decoration: BoxDecoration(gradient: _backgroundGradient), decoration: BoxDecoration(gradient: _backgroundGradient),
width: MediaQuery.of(context).size.width, child: Container(
height: MediaQuery.of(context).size.height, decoration: BoxDecoration(gradient: _backgroundGradient),
child: SafeArea( width: MediaQuery.of(context).size.width,
child: Padding( height: MediaQuery.of(context).size.height,
padding: EdgeInsets.only( child: SafeArea(
left: 24.0, child: Padding(
right: 24.0, padding: EdgeInsets.only(
top: 26.0 + MediaQuery.of(context).padding.top, left: 24.0,
bottom: 52.0, right: 24.0,
top: MediaQuery.of(context).padding.top,
bottom: 52.0,
),
child: widget.currentPage == 'grades'
? const GradesBody()
: widget.currentPage == 'lessons'
? const LessonsBody()
: widget.currentPage == 'allsum'
? const GradesBody()
: const PersonalityBody(),
), ),
child: widget.currentPage == 'grades'
? const GradesBody()
: widget.currentPage == 'lessons'
? const LessonsBody()
: widget.currentPage == 'allsum'
? const GradesBody()
: const PersonalityBody(),
), ),
), ),
), ),