From 72a538f3c51b69c1c022f694b9426c5751b14351 Mon Sep 17 00:00:00 2001 From: Armand <4831c0@proton.me> Date: Fri, 15 Aug 2025 13:31:35 +0200 Subject: [PATCH] refactor --- firka/lib/helpers/extensions.dart | 13 +++-- firka/lib/helpers/settings/setting.dart | 8 ++-- firka/lib/helpers/ui/firka_card.dart | 44 ++++++++++++----- firka/lib/main.dart | 9 ++-- .../lib/ui/phone/pages/home/home_grades.dart | 13 +++-- .../phone/pages/home/home_grades_subject.dart | 5 +- firka/lib/ui/phone/pages/home/home_main.dart | 23 ++++----- .../ui/phone/pages/home/home_timetable.dart | 26 +++++----- .../ui/phone/screens/debug/debug_screen.dart | 42 ++++++++-------- .../ui/phone/screens/home/home_screen.dart | 41 ++++++++-------- .../ui/phone/screens/login/login_screen.dart | 21 ++++---- .../screens/settings/settings_screen.dart | 20 ++++---- .../screens/wear_login/wear_login_screen.dart | 5 +- .../lib/ui/phone/widgets/bottom_nav_icon.dart | 2 +- .../lib/ui/phone/widgets/bottom_tt_icon.dart | 9 ++-- .../widgets/home_main_starting_soon.dart | 17 +++---- .../ui/phone/widgets/home_main_welcome.dart | 48 ++++++++++--------- firka/lib/ui/phone/widgets/lesson.dart | 30 +++++++----- firka/lib/ui/phone/widgets/lesson_big.dart | 28 +++++------ firka/lib/ui/phone/widgets/lesson_small.dart | 7 ++- firka/lib/ui/widget/class_icon.dart | 2 +- firka/lib/ui/widget/firka_icon.dart | 8 ++-- 22 files changed, 224 insertions(+), 197 deletions(-) diff --git a/firka/lib/helpers/extensions.dart b/firka/lib/helpers/extensions.dart index 26b487f9..cc8c77e9 100644 --- a/firka/lib/helpers/extensions.dart +++ b/firka/lib/helpers/extensions.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import '../l10n/app_localizations.dart'; @@ -39,7 +38,7 @@ enum FormatMode { yearly, grades, welcome, hmm, da, dd } enum Cycle { morning, day, afternoon, night } extension DateExtension on DateTime { - String format(BuildContext context, FormatMode mode) { + String format(AppLocalizations l10n, FormatMode mode) { var today = timeNow(); today = today.subtract(Duration( hours: today.hour, @@ -55,19 +54,19 @@ extension DateExtension on DateTime { switch (mode) { case FormatMode.grades: if (isBefore(yesterdayLim)) { - return format(context, FormatMode.yearly); + return format(l10n, FormatMode.yearly); } if (isAfter(yesterdayLim) && isBefore(today)) { - return AppLocalizations.of(context)!.yesterday; + return l10n.yesterday; } if (isAfter(yesterday) && isBefore(tomorrow)) { - return AppLocalizations.of(context)!.today; + return l10n.today; } if (isAfter(today) && isBefore(tomorrowLim)) { - return AppLocalizations.of(context)!.tomorrow; + return l10n.tomorrow; } - return format(context, FormatMode.yearly); + return format(l10n, FormatMode.yearly); case FormatMode.yearly: return DateFormat('MMMM dd').format(this); case FormatMode.hmm: diff --git a/firka/lib/helpers/settings/setting.dart b/firka/lib/helpers/settings/setting.dart index a937fa34..8afdd8e1 100644 --- a/firka/lib/helpers/settings/setting.dart +++ b/firka/lib/helpers/settings/setting.dart @@ -25,7 +25,7 @@ class SettingsStore { "settings_padding": SettingsPadding(0, 20), "application": SettingsSubGroup( 0, - FirkaIconType.Majesticons, + FirkaIconType.majesticons, Majesticon.settingsCogSolid, "Alkalmazás", LinkedHashMap.of({ @@ -60,13 +60,13 @@ class SettingsStore { })), "customization": SettingsSubGroup( 0, - FirkaIconType.Majesticons, + FirkaIconType.majesticons, Majesticon.flower2Solid, "Személyre szabás", LinkedHashMap.of({})), - "notifications": SettingsSubGroup(0, FirkaIconType.Majesticons, + "notifications": SettingsSubGroup(0, FirkaIconType.majesticons, Majesticon.bellSolid, "Értesítések", LinkedHashMap.of({})), - "extras": SettingsSubGroup(0, FirkaIconType.Majesticons, + "extras": SettingsSubGroup(0, FirkaIconType.majesticons, Majesticon.lightningBoltSolid, "Extrák", LinkedHashMap.of({})), "settings_other_padding": SettingsPadding(0, 20), "settings_other_header": SettingsHeaderSmall(0, "Egyéb"), diff --git a/firka/lib/helpers/ui/firka_card.dart b/firka/lib/helpers/ui/firka_card.dart index 506de966..22199d22 100644 --- a/firka/lib/helpers/ui/firka_card.dart +++ b/firka/lib/helpers/ui/firka_card.dart @@ -17,25 +17,36 @@ class FirkaCard extends StatelessWidget { Widget build(BuildContext context) { var right = this.right ?? []; - var _attached = attached != null ? attached! : Attach.none; + var attached = this.attached != null ? this.attached! : Attach.none; final defaultRounding = 16.0; final attachedRounding = 8.0; if (extra != null) { return SizedBox( - width: MediaQuery.of(context).size.width, + width: MediaQuery + .of(context) + .size + .width, child: Card( color: appStyle.colors.card, shape: RoundedRectangleBorder( borderRadius: BorderRadius.only( topLeft: Radius.circular( - _attached == Attach.top ? attachedRounding : defaultRounding), + attached == Attach.top + ? attachedRounding + : defaultRounding), topRight: Radius.circular( - _attached == Attach.top ? attachedRounding : defaultRounding), + attached == Attach.top + ? attachedRounding + : defaultRounding), bottomLeft: Radius.circular( - _attached == Attach.bottom ? attachedRounding : defaultRounding), + attached == Attach.bottom + ? attachedRounding + : defaultRounding), bottomRight: Radius.circular( - _attached == Attach.bottom ? attachedRounding : defaultRounding)), + attached == Attach.bottom + ? attachedRounding + : defaultRounding)), ), child: Padding( padding: const EdgeInsets.all(16.0), @@ -56,19 +67,30 @@ class FirkaCard extends StatelessWidget { ); } else { return SizedBox( - width: MediaQuery.of(context).size.width, + width: MediaQuery + .of(context) + .size + .width, child: Card( color: appStyle.colors.card, shape: RoundedRectangleBorder( borderRadius: BorderRadius.only( topLeft: Radius.circular( - _attached == Attach.top ? attachedRounding : defaultRounding), + attached == Attach.top + ? attachedRounding + : defaultRounding), topRight: Radius.circular( - _attached == Attach.top ? attachedRounding : defaultRounding), + attached == Attach.top + ? attachedRounding + : defaultRounding), bottomLeft: Radius.circular( - _attached == Attach.bottom ? attachedRounding : defaultRounding), + attached == Attach.bottom + ? attachedRounding + : defaultRounding), bottomRight: Radius.circular( - _attached == Attach.bottom ? attachedRounding : defaultRounding)), + attached == Attach.bottom + ? attachedRounding + : defaultRounding)), ), child: Padding( padding: const EdgeInsets.all(16.0), diff --git a/firka/lib/main.dart b/firka/lib/main.dart index 953ab7cc..2f117f33 100644 --- a/firka/lib/main.dart +++ b/firka/lib/main.dart @@ -10,6 +10,7 @@ import 'package:firka/helpers/db/models/token_model.dart'; import 'package:firka/helpers/db/widget.dart'; import 'package:firka/helpers/extensions.dart'; import 'package:firka/helpers/settings/setting.dart'; +import 'package:firka/l10n/app_localizations_hu.dart'; import 'package:firka/ui/model/style.dart'; import 'package:firka/ui/phone/pages/error/error_page.dart'; import 'package:firka/ui/phone/screens/debug/debug_screen.dart'; @@ -41,11 +42,13 @@ class AppInitialization { bool hasWatchListener = false; Uint8List? profilePicture; SettingsStore settings; + AppLocalizations l10n; AppInitialization({ required this.isar, required this.tokenCount, required this.settings, + required this.l10n, }); } @@ -80,6 +83,7 @@ Future initializeApp() async { isar: isar, tokenCount: tokenCount, settings: SettingsStore(), + l10n: AppLocalizationsHu(), ); resetOldTimeTableCache(isar); @@ -128,13 +132,12 @@ void main() async { class InitializationScreen extends StatelessWidget { InitializationScreen({super.key}); - // Place to store the initialization future - final Future _initialization = initializeApp(); + final Future _init = initializeApp(); @override Widget build(BuildContext context) { return FutureBuilder( - future: _initialization, + future: _init, builder: (context, snapshot) { // Check if initialization is complete if (snapshot.connectionState == ConnectionState.done) { diff --git a/firka/lib/ui/phone/pages/home/home_grades.dart b/firka/lib/ui/phone/pages/home/home_grades.dart index 093ea898..282115d7 100644 --- a/firka/lib/ui/phone/pages/home/home_grades.dart +++ b/firka/lib/ui/phone/pages/home/home_grades.dart @@ -8,7 +8,6 @@ import 'package:flutter/material.dart'; import '../../../../helpers/api/model/subject.dart'; import '../../../../helpers/debug_helper.dart'; -import '../../../../l10n/app_localizations.dart'; import '../../../../main.dart'; import '../../../model/style.dart'; @@ -82,7 +81,7 @@ class HomeGradesScreen extends StatelessAsyncWidget { Row( children: [ Text( - AppLocalizations.of(context)!.subjects, + data.l10n.subjects, style: appStyle.fonts.H_H2 .apply(color: appStyle.colors.textSecondary), ) @@ -97,7 +96,7 @@ class HomeGradesScreen extends StatelessAsyncWidget { child: ListView( children: [ Text( - AppLocalizations.of(context)!.your_subjects, + data.l10n.your_subjects, style: appStyle.fonts.H_14px .apply(color: appStyle.colors.textSecondary), ), @@ -105,7 +104,7 @@ class HomeGradesScreen extends StatelessAsyncWidget { ...gradeCards, SizedBox(height: 16), Text( - AppLocalizations.of(context)!.data, + data.l10n.data, style: appStyle.fonts.B_16SB .apply(color: appStyle.colors.textSecondary), ), @@ -113,7 +112,7 @@ class HomeGradesScreen extends StatelessAsyncWidget { FirkaCard( left: [ Text( - AppLocalizations.of(context)!.subject_avg, + data.l10n.subject_avg, style: appStyle.fonts.B_16SB .apply(color: appStyle.colors.textPrimary), ), @@ -136,7 +135,7 @@ class HomeGradesScreen extends StatelessAsyncWidget { ), FirkaCard(left: [ Text( - AppLocalizations.of(context)!.class_avg, + data.l10n.class_avg, style: appStyle.fonts.B_16SB .apply(color: appStyle.colors.textPrimary), ), @@ -144,7 +143,7 @@ class HomeGradesScreen extends StatelessAsyncWidget { FirkaCard( left: [ Text( - AppLocalizations.of(context)!.class_n, + data.l10n.class_n, style: appStyle.fonts.B_16SB .apply(color: appStyle.colors.textPrimary), ), diff --git a/firka/lib/ui/phone/pages/home/home_grades_subject.dart b/firka/lib/ui/phone/pages/home/home_grades_subject.dart index 89800fac..1bc9d2e9 100644 --- a/firka/lib/ui/phone/pages/home/home_grades_subject.dart +++ b/firka/lib/ui/phone/pages/home/home_grades_subject.dart @@ -4,7 +4,6 @@ import 'package:firka/helpers/ui/grade.dart'; import 'package:firka/helpers/ui/stateless_async_widget.dart'; import 'package:flutter/material.dart'; -import '../../../../l10n/app_localizations.dart'; import '../../../../main.dart'; import '../../../model/style.dart'; @@ -30,7 +29,7 @@ class HomeGradesSubjectScreen extends StatelessAsyncWidget { height: 8, )); gradeWidgets.add(Text( - group.key.format(context, FormatMode.grades), + group.key.format(data.l10n, FormatMode.grades), style: appStyle.fonts.H_14px, )); gradeWidgets.add(SizedBox( @@ -75,7 +74,7 @@ class HomeGradesSubjectScreen extends StatelessAsyncWidget { Row( children: [ Text( - AppLocalizations.of(context)!.subjects, + data.l10n.subjects, style: appStyle .fonts.H_16px // TODO: Replace this with the proper font .apply(color: appStyle.colors.textPrimary), diff --git a/firka/lib/ui/phone/pages/home/home_main.dart b/firka/lib/ui/phone/pages/home/home_main.dart index 446f7c24..fedfefef 100644 --- a/firka/lib/ui/phone/pages/home/home_main.dart +++ b/firka/lib/ui/phone/pages/home/home_main.dart @@ -19,13 +19,11 @@ class HomeMainScreen extends StatefulWidget { const HomeMainScreen(this.data, {super.key}); @override - State createState() => _HomeMainScreen(data); + State createState() => _HomeMainScreen(); } class _HomeMainScreen extends State { - final AppInitialization data; - - _HomeMainScreen(this.data); + _HomeMainScreen(); DateTime now = timeNow(); List? lessons; @@ -40,7 +38,7 @@ class _HomeMainScreen extends State { now = timeNow(); var midnight = now.getMidnight(); (() async { - var resp = await data.client.getTimeTable( + var resp = await widget.data.client.getTimeTable( midnight, midnight.add(Duration(hours: 23, minutes: 59))); if (disposed) return; @@ -49,7 +47,7 @@ class _HomeMainScreen extends State { }); })(); (() async { - var resp = await data.client.getStudent(); + var resp = await widget.data.client.getStudent(); if (disposed) return; setState(() { @@ -81,7 +79,7 @@ class _HomeMainScreen extends State { if (lessons != null && lessons!.isNotEmpty) { if (now.isBefore(lessons!.first.start)) { - welcomeWidget = StartingSoonWidget(now, lessons!); + welcomeWidget = StartingSoonWidget(widget.data.l10n, now, lessons!); } else { var currentLesson = lessons!.firstWhereOrNull( (lesson) => now.isAfter(lesson.start) && now.isBefore(lesson.end)); @@ -97,13 +95,16 @@ class _HomeMainScreen extends State { lessonActive = true; } - welcomeWidget = LessonBigWidget( - now, lessonIndex, currentLesson, prevLesson, nextLesson); + welcomeWidget = LessonBigWidget(widget.data.l10n, now, lessonIndex, + currentLesson, prevLesson, nextLesson); } } if (lessons != null && lessons!.isNotEmpty) { var nextLesson = lessons!.getNextLesson(now); - if (nextLesson != null) nextClass = LessonSmallWidget(nextLesson, lessonActive); + if (nextLesson != null) { + nextClass = + LessonSmallWidget(widget.data.l10n, nextLesson, lessonActive); + } } if (student != null && lessons != null) { @@ -117,7 +118,7 @@ class _HomeMainScreen extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ - WelcomeWidget(now, student!, lessons!), + WelcomeWidget(widget.data.l10n, now, student!, lessons!), SizedBox(height: 48), welcomeWidget, lessonActive ? SizedBox(height: 5) : SizedBox(height: 0), diff --git a/firka/lib/ui/phone/pages/home/home_timetable.dart b/firka/lib/ui/phone/pages/home/home_timetable.dart index 78c8ba6b..4998a3c1 100644 --- a/firka/lib/ui/phone/pages/home/home_timetable.dart +++ b/firka/lib/ui/phone/pages/home/home_timetable.dart @@ -1,7 +1,6 @@ import 'package:firka/helpers/api/model/timetable.dart'; import 'package:firka/helpers/debug_helper.dart'; import 'package:firka/helpers/extensions.dart'; -import 'package:firka/l10n/app_localizations.dart'; import 'package:firka/ui/model/style.dart'; import 'package:firka/ui/phone/widgets/bottom_tt_icon.dart'; import 'package:firka/ui/phone/widgets/lesson.dart'; @@ -15,19 +14,20 @@ import '../../../../main.dart'; class HomeTimetableScreen extends StatefulWidget { final AppInitialization data; + const HomeTimetableScreen(this.data, {super.key}); @override - State createState() => _HomeTimetableScreen(data); + State createState() => _HomeTimetableScreen(); } class _HomeTimetableScreen extends State { - final AppInitialization data; List? lessons; List? dates; DateTime? active; bool disposed = false; - _HomeTimetableScreen(this.data); + + _HomeTimetableScreen(); @override void dispose() { @@ -44,7 +44,7 @@ class _HomeTimetableScreen extends State { var sunday = monday.add(Duration(days: 6)); (() async { - var lessonsResp = await data.client.getTimeTable(monday, sunday); + var lessonsResp = await widget.data.client.getTimeTable(monday, sunday); List dates = List.empty(growable: true); if (lessonsResp.response != null) { @@ -89,7 +89,7 @@ class _HomeTimetableScreen extends State { .toList(); for (final date in dates!) { - ttWidgets.add(BottomTimeTableNavIconWidget(() { + ttWidgets.add(BottomTimeTableNavIconWidget(widget.data.l10n, () { setState(() { active = date; }); @@ -109,8 +109,8 @@ class _HomeTimetableScreen extends State { SvgPicture.asset("assets/images/logos/dave.svg", width: 48, height: 48), SizedBox(height: 12), - Text(AppLocalizations.of(context)!.tt_no_classes_l1), - Text(AppLocalizations.of(context)!.tt_no_classes_l2) + Text(widget.data.l10n.tt_no_classes_l1), + Text(widget.data.l10n.tt_no_classes_l2) ]), ); } else { @@ -118,7 +118,7 @@ class _HomeTimetableScreen extends State { var lesson = lessonsToday[i]; Lesson? nextLesson = lessonsToday.length > i + 1 ? lessonsToday[i + 1] : null; - ttBody.add(LessonWidget( + ttBody.add(LessonWidget(widget.data.l10n, lessonsToday.getLessonNo(lesson), lesson, nextLesson)); } } @@ -138,7 +138,7 @@ class _HomeTimetableScreen extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - AppLocalizations.of(context)!.timetable, + widget.data.l10n.timetable, style: appStyle.fonts.H_H2 .apply(color: appStyle.colors.textPrimary), ), @@ -149,7 +149,7 @@ class _HomeTimetableScreen extends State { child: Padding( padding: const EdgeInsets.all(8), child: FirkaIconWidget( - FirkaIconType.Majesticons, + FirkaIconType.majesticons, Majesticon.tableSolid, size: 26.0, color: appStyle.colors.accent, @@ -161,7 +161,7 @@ class _HomeTimetableScreen extends State { child: Padding( padding: const EdgeInsets.all(4), child: FirkaIconWidget( - FirkaIconType.Majesticons, + FirkaIconType.majesticons, Majesticon.plusLine, size: 32.0, color: appStyle.colors.accent, @@ -173,7 +173,7 @@ class _HomeTimetableScreen extends State { child: Padding( padding: const EdgeInsets.all(8), child: FirkaIconWidget( - FirkaIconType.Majesticons, + FirkaIconType.majesticons, Majesticon.settingsCogSolid, size: 26.0, color: appStyle.colors.accent, diff --git a/firka/lib/ui/phone/screens/debug/debug_screen.dart b/firka/lib/ui/phone/screens/debug/debug_screen.dart index 0a239e99..bd8eeebd 100644 --- a/firka/lib/ui/phone/screens/debug/debug_screen.dart +++ b/firka/lib/ui/phone/screens/debug/debug_screen.dart @@ -7,7 +7,6 @@ import 'package:firka/helpers/extensions.dart'; import 'package:firka/helpers/icon_helper.dart'; import 'package:firka/helpers/profile_picture.dart'; import 'package:firka/main.dart'; -import 'package:firka/ui/model/style.dart'; import 'package:firka/ui/phone/screens/login/login_screen.dart'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; @@ -21,13 +20,11 @@ class DebugScreen extends StatefulWidget { const DebugScreen(this.data, {super.key}); @override - State createState() => _DebugScreen(data); + State createState() => _DebugScreen(); } class _DebugScreen extends State { - final AppInitialization data; - - _DebugScreen(this.data); + _DebugScreen(); late ImagePicker _picker; Uint8List? profilePictureData; @@ -39,7 +36,7 @@ class _DebugScreen extends State { super.initState(); _picker = ImagePicker(); - profilePictureData = data.profilePicture; + profilePictureData = widget.data.profilePicture; } @override @@ -98,11 +95,11 @@ class _DebugScreen extends State { profilePicture, ElevatedButton( onPressed: () async { - await pickProfilePicture(data, _picker); + await pickProfilePicture(widget.data, _picker); setState(() { - if (data.profilePicture != null) { - profilePictureData = data.profilePicture; + if (widget.data.profilePicture != null) { + profilePictureData = widget.data.profilePicture; } }); }, @@ -139,21 +136,21 @@ class _DebugScreen extends State { ElevatedButton( onPressed: () async { print( - "getStudent(): ${await data.client.getStudent(forceCache: useCache)}"); + "getStudent(): ${await widget.data.client.getStudent(forceCache: useCache)}"); }, child: const Text('getStudent()'), ), ElevatedButton( onPressed: () async { print( - "getNoticeBoard(): ${await data.client.getNoticeBoard(forceCache: useCache)}"); + "getNoticeBoard(): ${await widget.data.client.getNoticeBoard(forceCache: useCache)}"); }, child: const Text('getNoticeBoard()'), ), ElevatedButton( onPressed: () async { print( - "getGrades(): ${await data.client.getGrades(forceCache: useCache)}"); + "getGrades(): ${await widget.data.client.getGrades(forceCache: useCache)}"); }, child: const Text('getGrades()'), ), @@ -165,7 +162,7 @@ class _DebugScreen extends State { var end = now.add(Duration(days: 7)); print( - "getLessons(): ${await data.client.getTimeTable(start, end, forceCache: useCache)}"); + "getLessons(): ${await widget.data.client.getTimeTable(start, end, forceCache: useCache)}"); }, child: const Text('getLessons()'), ), @@ -177,21 +174,21 @@ class _DebugScreen extends State { var end = now.add(Duration(days: 14)); print( - "getHomework(): ${await data.client.getHomework(start, end, forceCache: useCache)}"); + "getHomework(): ${await widget.data.client.getHomework(start, end, forceCache: useCache)}"); }, child: const Text('getHomework()'), ), ElevatedButton( onPressed: () async { print( - "getTests(): ${await data.client.getTests(forceCache: useCache)}"); + "getTests(): ${await widget.data.client.getTests(forceCache: useCache)}"); }, child: const Text('getTests()'), ), ElevatedButton( onPressed: () async { print( - "getOmissions(): ${await data.client.getOmissions(forceCache: useCache)}"); + "getOmissions(): ${await widget.data.client.getOmissions(forceCache: useCache)}"); }, child: const Text('getOmissions()'), ), @@ -203,12 +200,13 @@ class _DebugScreen extends State { ), ElevatedButton( style: ButtonStyle( - backgroundColor: WidgetStateProperty.fromMap({ + backgroundColor: WidgetStateProperty< + Color>.fromMap({ WidgetState.any: Colors.red, }), ), onPressed: () async { - var isar = data.isar; + var isar = widget.data.isar; await isar.writeTxn(() async { await isar.tokenModels.clear(); @@ -217,9 +215,9 @@ class _DebugScreen extends State { widget.data.tokenCount = 0; Navigator.push( - context, - MaterialPageRoute( - builder: (context) => LoginScreen(data))); + context, + MaterialPageRoute( + builder: (context) => LoginScreen(widget.data))); }, child: const Text('wipe users'), ), @@ -238,7 +236,7 @@ class _DebugScreen extends State { ), Center( child: FirkaIconWidget( - FirkaIconType.Majesticons, getIconData(e), + FirkaIconType.majesticons, getIconData(e), color: Colors.black), ) ], diff --git a/firka/lib/ui/phone/screens/home/home_screen.dart b/firka/lib/ui/phone/screens/home/home_screen.dart index b5b75600..c17e8285 100644 --- a/firka/lib/ui/phone/screens/home/home_screen.dart +++ b/firka/lib/ui/phone/screens/home/home_screen.dart @@ -15,7 +15,6 @@ import 'package:majesticons_flutter/majesticons_flutter.dart'; import '../../../../helpers/db/widget.dart'; import '../../../../helpers/debug_helper.dart'; -import '../../../../l10n/app_localizations.dart'; import '../../../widget/firka_icon.dart'; import '../../pages/extras/extras.dart'; import '../../pages/extras/main_error.dart'; @@ -28,7 +27,7 @@ class HomeScreen extends StatefulWidget { const HomeScreen(this.data, {super.key}); @override - State createState() => _HomeScreenState(data); + State createState() => _HomeScreenState(); } enum HomePages { home, grades, timetable } @@ -55,9 +54,7 @@ bool _prefetched = false; bool canPop = true; class _HomeScreenState extends State { - final AppInitialization data; - - _HomeScreenState(this.data); + _HomeScreenState(); ActiveHomePage page = ActiveHomePage(HomePages.home); List previousPages = List.empty(growable: true); @@ -81,9 +78,12 @@ class _HomeScreenState extends State { _prefetched = true; var random = Random(); - ApiResponse res = await data.client.getGrades(forceCache: false); + ApiResponse res = + await widget.data.client.getGrades(forceCache: false); - if (res.err != null) throw "await data.client.getGrades\n${res.err!}"; + if (res.err != null) { + throw "await widget.data.client.getGrades\n${res.err!}"; + } await Future.delayed(Duration(seconds: 1 + random.nextInt(2))); @@ -91,10 +91,13 @@ class _HomeScreenState extends State { var start = now.subtract(Duration(days: now.weekday - 1)); var end = start.add(Duration(days: 6)); - res = await data.client.getTimeTable(start, end, forceCache: false); - if (res.err != null) throw "await data.client.getTimeTable\n${res.err!}"; + res = + await widget.data.client.getTimeTable(start, end, forceCache: false); + if (res.err != null) { + throw "await widget.data.client.getTimeTable\n${res.err!}"; + } - await WidgetCacheHelper.updateWidgetCache(appStyle, data.client); + await WidgetCacheHelper.updateWidgetCache(appStyle, widget.data.client); await HomeWidget.updateWidget( qualifiedAndroidName: "app.firka.naplo.glance.TimetableWidget"); } catch (e) { @@ -129,13 +132,13 @@ class _HomeScreenState extends State { // Use min to prevent filling the width children: [ Text( - AppLocalizations.of(context)!.api_error, + widget.data.l10n.api_error, style: appStyle.fonts.B_14SB .copyWith(color: appStyle.colors.errorText), ), SizedBox(width: 8), GestureDetector( - child: FirkaIconWidget(FirkaIconType.Majesticons, + child: FirkaIconWidget(FirkaIconType.majesticons, Majesticon.questionCircleSolid, color: appStyle.colors.errorAccent, size: 24), onTap: () { @@ -214,7 +217,7 @@ class _HomeScreenState extends State { ), SizedBox(width: 16), Text( - AppLocalizations.of(context)!.refreshing, + widget.data.l10n.refreshing, style: appStyle.fonts.B_14SB .copyWith(color: appStyle.colors.textPrimary), ) @@ -242,7 +245,7 @@ class _HomeScreenState extends State { children: [ Row( mainAxisAlignment: MainAxisAlignment.center, - children: [HomeSubPage(page, setPageCB, data)], + children: [HomeSubPage(page, setPageCB, widget.data)], ), Container( decoration: BoxDecoration( @@ -279,7 +282,7 @@ class _HomeScreenState extends State { page.page == HomePages.home ? Majesticon.homeSolid : Majesticon.homeLine, - AppLocalizations.of(context)!.home, + widget.data.l10n.home, page.page == HomePages.home ? appStyle.colors.accent : appStyle.colors.secondary, @@ -300,7 +303,7 @@ class _HomeScreenState extends State { page.page == HomePages.grades ? Majesticon.bookmarkSolid : Majesticon.bookmarkLine, - AppLocalizations.of(context)!.grades, + widget.data.l10n.grades, page.page == HomePages.grades ? appStyle.colors.accent : appStyle.colors.secondary, @@ -321,7 +324,7 @@ class _HomeScreenState extends State { page.page == HomePages.timetable ? Majesticon.calendarSolid : Majesticon.calendarLine, - AppLocalizations.of(context)!.timetable, + widget.data.l10n.timetable, page.page == HomePages.timetable ? appStyle.colors.accent : appStyle.colors.secondary, @@ -329,11 +332,11 @@ class _HomeScreenState extends State { // More Button BottomNavIconWidget(() { HapticFeedback.lightImpact(); - showExtrasBottomSheet(context, data); + showExtrasBottomSheet(context, widget.data); }, false, Majesticon.globeEarthLine, - AppLocalizations.of(context)!.other, + widget.data.l10n.other, appStyle.colors.secondary, appStyle.colors.textPrimary), ], diff --git a/firka/lib/ui/phone/screens/login/login_screen.dart b/firka/lib/ui/phone/screens/login/login_screen.dart index 97ea321f..704fff77 100644 --- a/firka/lib/ui/phone/screens/login/login_screen.dart +++ b/firka/lib/ui/phone/screens/login/login_screen.dart @@ -11,7 +11,6 @@ import 'package:flutter/services.dart'; import 'package:webview_flutter/webview_flutter.dart'; import '../../../../helpers/api/token_grant.dart'; -import '../../../../l10n/app_localizations.dart'; import '../../../model/style.dart'; import '../home/home_screen.dart'; @@ -101,8 +100,8 @@ class _LoginScreenState extends State { MediaQuery.of(context).size.width * 0.95; List> slides = [ { - 'title': AppLocalizations.of(context)!.title1, - 'subtitle': AppLocalizations.of(context)!.subtitle1, + 'title': widget.data.l10n.title1, + 'subtitle': widget.data.l10n.subtitle1, 'picture': 'assets/images/carousel/slide1.png', 'background': 'assets/images/carousel/slide1_background.gif', 'foreground': '', @@ -113,8 +112,8 @@ class _LoginScreenState extends State { 'y': 150.00, }, { - 'title': AppLocalizations.of(context)!.title2, - 'subtitle': AppLocalizations.of(context)!.subtitle2, + 'title': widget.data.l10n.title2, + 'subtitle': widget.data.l10n.subtitle2, 'picture': 'assets/images/carousel/slide2.png', 'background': 'assets/images/carousel/slide2_background.gif', 'foreground': '', @@ -125,8 +124,8 @@ class _LoginScreenState extends State { 'y': 160.00, }, { - 'title': AppLocalizations.of(context)!.title3, - 'subtitle': AppLocalizations.of(context)!.subtitle3, + 'title': widget.data.l10n.title3, + 'subtitle': widget.data.l10n.subtitle3, 'picture': 'assets/images/carousel/slide3.png', 'background': '', 'foreground': 'assets/images/carousel/slide3_foreground.gif', @@ -136,8 +135,8 @@ class _LoginScreenState extends State { 'y': 25.00, }, { - 'title': AppLocalizations.of(context)!.title4, - 'subtitle': AppLocalizations.of(context)!.subtitle4, + 'title': widget.data.l10n.title4, + 'subtitle': widget.data.l10n.subtitle4, 'picture': 'assets/images/carousel/slide4.png', 'background': 'assets/images/carousel/slide4_background.gif', 'foreground': '', @@ -431,7 +430,7 @@ class _LoginScreenState extends State { ), child: Center( child: Text( - AppLocalizations.of(context)!.loginBtn, + widget.data.l10n.loginBtn, textAlign: TextAlign.center, style: appStyle.fonts.H_16px.copyWith( color: appStyle.colors.textPrimary, @@ -445,7 +444,7 @@ class _LoginScreenState extends State { const SizedBox(height: 20), GestureDetector( child: Text( - AppLocalizations.of(context)!.privacyLabel, + widget.data.l10n.privacyLabel, textAlign: TextAlign.center, style: appStyle.fonts.H_12px .copyWith(color: appStyle.colors.textTertiary), diff --git a/firka/lib/ui/phone/screens/settings/settings_screen.dart b/firka/lib/ui/phone/screens/settings/settings_screen.dart index cd95cd80..597972f5 100644 --- a/firka/lib/ui/phone/screens/settings/settings_screen.dart +++ b/firka/lib/ui/phone/screens/settings/settings_screen.dart @@ -17,14 +17,11 @@ class SettingsScreen extends StatefulWidget { const SettingsScreen(this.data, this.items, {super.key}); @override - State createState() => _SettingsScreenState(data, items); + State createState() => _SettingsScreenState(); } class _SettingsScreenState extends State { - final AppInitialization data; - final LinkedHashMap items; - - _SettingsScreenState(this.data, this.items); + _SettingsScreenState(); @override void initState() { @@ -92,7 +89,8 @@ class _SettingsScreenState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => SettingsScreen(data, item.children))); + builder: (context) => + SettingsScreen(widget.data, item.children))); }, child: FirkaCard(left: cardWidgets), )); @@ -127,8 +125,8 @@ class _SettingsScreenState extends State { item.value = v; }); - data.isar.writeTxn(() async { - item.save(data.isar.appSettingsModels); + widget.data.isar.writeTxn(() async { + item.save(widget.data.isar.appSettingsModels); }); }) ], @@ -154,8 +152,8 @@ class _SettingsScreenState extends State { item.activeIndex = i; }); - data.isar.writeTxn(() async { - item.save(data.isar.appSettingsModels); + widget.data.isar.writeTxn(() async { + item.save(widget.data.isar.appSettingsModels); }); }) ])); @@ -170,7 +168,7 @@ class _SettingsScreenState extends State { Widget build(BuildContext context) { _updateSystemUI(); // Update system UI on every build, to compensate for the android system being dumb - var body = createWidgetTree(items.values); + var body = createWidgetTree(widget.items.values); return Scaffold( backgroundColor: appStyle.colors.background, diff --git a/firka/lib/ui/phone/screens/wear_login/wear_login_screen.dart b/firka/lib/ui/phone/screens/wear_login/wear_login_screen.dart index 32721502..3eab020e 100644 --- a/firka/lib/ui/phone/screens/wear_login/wear_login_screen.dart +++ b/firka/lib/ui/phone/screens/wear_login/wear_login_screen.dart @@ -17,14 +17,13 @@ class WearLoginScreen extends StatefulWidget { const WearLoginScreen(this.data, {super.key}); @override - State createState() => _WearLoginScreenState(data); + State createState() => _WearLoginScreenState(); } class _WearLoginScreenState extends State { late WebViewController _webViewController; - final AppInitialization data; - _WearLoginScreenState(this.data); + _WearLoginScreenState(); final watch = WatchConnectivity(); diff --git a/firka/lib/ui/phone/widgets/bottom_nav_icon.dart b/firka/lib/ui/phone/widgets/bottom_nav_icon.dart index adc220bb..9f6cc8c4 100644 --- a/firka/lib/ui/phone/widgets/bottom_nav_icon.dart +++ b/firka/lib/ui/phone/widgets/bottom_nav_icon.dart @@ -30,7 +30,7 @@ class BottomNavIconWidget extends StatelessWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ - FirkaIconWidget(FirkaIconType.Majesticons, icon, + FirkaIconWidget(FirkaIconType.majesticons, icon, color: iconColor, size: 24) .build(context), const SizedBox(height: 4), diff --git a/firka/lib/ui/phone/widgets/bottom_tt_icon.dart b/firka/lib/ui/phone/widgets/bottom_tt_icon.dart index 063aa1b1..016e59fb 100644 --- a/firka/lib/ui/phone/widgets/bottom_tt_icon.dart +++ b/firka/lib/ui/phone/widgets/bottom_tt_icon.dart @@ -1,14 +1,17 @@ import 'package:firka/helpers/extensions.dart'; +import 'package:firka/l10n/app_localizations.dart'; import 'package:flutter/material.dart'; import '../../model/style.dart'; class BottomTimeTableNavIconWidget extends StatelessWidget { + final AppLocalizations l10n; final void Function() onTap; final bool active; final DateTime date; - const BottomTimeTableNavIconWidget(this.onTap, this.active, this.date, + const BottomTimeTableNavIconWidget( + this.l10n, this.onTap, this.active, this.date, {super.key}); @override @@ -28,11 +31,11 @@ class BottomTimeTableNavIconWidget extends StatelessWidget { child: Column( children: [ SizedBox(height: 6), - Text(date.format(context, FormatMode.da), + Text(date.format(l10n, FormatMode.da), style: appStyle.fonts.H_16px .apply(color: appStyle.colors.textPrimary)), Text( - date.format(context, FormatMode.dd), + date.format(l10n, FormatMode.dd), style: appStyle.fonts.B_14R .apply(color: appStyle.colors.textSecondary), ) diff --git a/firka/lib/ui/phone/widgets/home_main_starting_soon.dart b/firka/lib/ui/phone/widgets/home_main_starting_soon.dart index 21ab6274..ee85313d 100644 --- a/firka/lib/ui/phone/widgets/home_main_starting_soon.dart +++ b/firka/lib/ui/phone/widgets/home_main_starting_soon.dart @@ -7,10 +7,11 @@ import 'package:flutter/material.dart'; import '../../../helpers/api/model/timetable.dart'; class StartingSoonWidget extends StatelessWidget { + final AppLocalizations l10n; final List lessons; final DateTime now; - const StartingSoonWidget(this.now, this.lessons, {super.key}); + const StartingSoonWidget(this.l10n, this.now, this.lessons, {super.key}); @override Widget build(BuildContext context) { @@ -19,15 +20,9 @@ class StartingSoonWidget extends StatelessWidget { var min = diff.inMinutes % 60; var sec = diff.inSeconds % 60; - var hourTxt = hour == 1 - ? AppLocalizations.of(context)!.starting_hour - : AppLocalizations.of(context)!.starting_hour_plural; - var minTxt = hour == 1 - ? AppLocalizations.of(context)!.starting_min - : AppLocalizations.of(context)!.starting_min_plural; - var secTxt = hour == 1 - ? AppLocalizations.of(context)!.starting_sec - : AppLocalizations.of(context)!.starting_sec_plural; + var hourTxt = hour == 1 ? l10n.starting_hour : l10n.starting_hour_plural; + var minTxt = hour == 1 ? l10n.starting_min : l10n.starting_min_plural; + var secTxt = hour == 1 ? l10n.starting_sec : l10n.starting_sec_plural; return Column( crossAxisAlignment: CrossAxisAlignment.center, @@ -42,7 +37,7 @@ class StartingSoonWidget extends StatelessWidget { children: [ SizedBox(width: 6), Text( - AppLocalizations.of(context)!.starting_soon, + l10n.starting_soon, style: appStyle.fonts.H_16px .apply(color: appStyle.colors.textPrimary), ), diff --git a/firka/lib/ui/phone/widgets/home_main_welcome.dart b/firka/lib/ui/phone/widgets/home_main_welcome.dart index b2c9b1e9..3d20c5de 100644 --- a/firka/lib/ui/phone/widgets/home_main_welcome.dart +++ b/firka/lib/ui/phone/widgets/home_main_welcome.dart @@ -9,44 +9,46 @@ import '../../../helpers/api/model/timetable.dart'; import '../../model/style.dart'; class WelcomeWidget extends StatelessWidget { + final AppLocalizations l10n; final Student student; final List lessons; final DateTime now; - const WelcomeWidget(this.now, this.student, this.lessons, {super.key}); + const WelcomeWidget(this.l10n, this.now, this.student, this.lessons, + {super.key}); getIconForCycle(Cycle dayCycle) { switch (dayCycle) { case Cycle.morning: - return FirkaIconWidget(FirkaIconType.MajesticonsLocal, "sunSolid", + return FirkaIconWidget(FirkaIconType.majesticonsLocal, "sunSolid", color: appStyle.colors.accent); case Cycle.day: return FirkaIconWidget( - FirkaIconType.MajesticonsLocal, "parkSolidSchool", + FirkaIconType.majesticonsLocal, "parkSolidSchool", color: appStyle.colors.accent); case Cycle.afternoon: - return FirkaIconWidget(FirkaIconType.Majesticons, Majesticon.moonSolid, + return FirkaIconWidget(FirkaIconType.majesticons, Majesticon.moonSolid, color: appStyle.colors.accent); case Cycle.night: - return FirkaIconWidget(FirkaIconType.Majesticons, Majesticon.moonSolid, + return FirkaIconWidget(FirkaIconType.majesticons, Majesticon.moonSolid, color: appStyle.colors.accent); } } - String getRawTitle(BuildContext context, String name, Cycle dayCycle) { + String getRawTitle(String name, Cycle dayCycle) { switch (dayCycle) { case Cycle.morning: - return AppLocalizations.of(context)!.good_morning(name); + return l10n.good_morning(name); case Cycle.day: - return AppLocalizations.of(context)!.good_day(name); + return l10n.good_day(name); case Cycle.afternoon: - return AppLocalizations.of(context)!.good_afternoon(name); + return l10n.good_afternoon(name); case Cycle.night: - return AppLocalizations.of(context)!.good_night(name); + return l10n.good_night(name); } } - String getTitle(BuildContext context, Cycle dayCycle) { + String getTitle(Cycle dayCycle) { var name = ""; try { @@ -56,35 +58,35 @@ class WelcomeWidget extends StatelessWidget { } if (lessons.isEmpty) { - return getRawTitle(context, name, dayCycle); + return getRawTitle(name, dayCycle); } else { if (now.isBefore(lessons.first.start)) { - return getRawTitle(context, name, dayCycle); + return getRawTitle(name, dayCycle); } - return getRawTitle(context, name, dayCycle); + return getRawTitle(name, dayCycle); } } - String getSubtitle(BuildContext context, Cycle dayCycle) { + String getSubtitle(Cycle dayCycle) { if (lessons.isEmpty) { - return now.format(context, FormatMode.welcome); + return now.format(l10n, FormatMode.welcome); } else { if (now.isBefore(lessons.first.start)) { - return now.format(context, FormatMode.welcome); + return now.format(l10n, FormatMode.welcome); } var lessonsLeft = lessons.where((lesson) => lesson.start.isAfter(now)).length; if (lessonsLeft < 1) { - return AppLocalizations.of(context)!.tomorrow_subtitle; + return l10n.tomorrow_subtitle; } if (lessonsLeft == 1) { - return AppLocalizations.of(context)!.suffering_almost_over_subtitle; + return l10n.suffering_almost_over_subtitle; } if (lessonsLeft <= 3) { - return AppLocalizations.of(context)!.n_left_subtitle(lessonsLeft); + return l10n.n_left_subtitle(lessonsLeft); } - return now.format(context, FormatMode.welcome); + return now.format(l10n, FormatMode.welcome); } } @@ -97,11 +99,11 @@ class WelcomeWidget extends StatelessWidget { children: [ getIconForCycle(dayCycle), const SizedBox(height: 16.0), - Text(getTitle(context, dayCycle), + Text(getTitle(dayCycle), style: appStyle.fonts.H_H2 .copyWith(color: appStyle.colors.textPrimary)), const SizedBox(height: 2.0), - Text(getSubtitle(context, dayCycle), + Text(getSubtitle(dayCycle), style: appStyle.fonts.B_14R .copyWith(color: appStyle.colors.textSecondary)), ], diff --git a/firka/lib/ui/phone/widgets/lesson.dart b/firka/lib/ui/phone/widgets/lesson.dart index b91c96c1..99632f9c 100644 --- a/firka/lib/ui/phone/widgets/lesson.dart +++ b/firka/lib/ui/phone/widgets/lesson.dart @@ -8,11 +8,13 @@ import '../../../helpers/api/model/timetable.dart'; import '../../widget/class_icon.dart'; class LessonWidget extends StatelessWidget { + final AppLocalizations l10n; final int? lessonNo; final Lesson lesson; final Lesson? nextLesson; - const LessonWidget(this.lessonNo, this.lesson, this.nextLesson, {super.key}); + const LessonWidget(this.l10n, this.lessonNo, this.lesson, this.nextLesson, + {super.key}); @override Widget build(BuildContext context) { @@ -39,7 +41,7 @@ class LessonWidget extends StatelessWidget { elements.add(GestureDetector( onTap: () { showLessonBottomSheet( - context, lesson, lessonNo, accent, secondary, bgColor); + context, l10n, lesson, lessonNo, accent, secondary, bgColor); }, child: FirkaCard( left: [ @@ -75,8 +77,8 @@ class LessonWidget extends StatelessWidget { right: [ Text( isDismissed - ? AppLocalizations.of(context)!.class_dismissed - : lesson.start.toLocal().format(context, FormatMode.hmm), + ? l10n.class_dismissed + : lesson.start.toLocal().format(l10n, FormatMode.hmm), style: appStyle.fonts.B_14R .apply(color: appStyle.colors.textPrimary)), isDismissed @@ -98,7 +100,7 @@ class LessonWidget extends StatelessWidget { if (isSubstituted) { elements.add(FirkaCard( left: [ - Text(AppLocalizations.of(context)!.class_substitution, + Text(l10n.class_substitution, style: appStyle.fonts.H_14px .apply(color: appStyle.colors.textPrimary)) ], @@ -116,13 +118,13 @@ class LessonWidget extends StatelessWidget { elements.add(FirkaCard( left: [ - Text(AppLocalizations.of(context)!.breakTxt, + Text(l10n.breakTxt, style: appStyle.fonts.B_14SB .apply(color: appStyle.colors.textSecondary)) ], right: [ Text( - "$breakMins ${breakMins == 1 ? AppLocalizations.of(context)!.starting_min : AppLocalizations.of(context)!.starting_min_plural}", + "$breakMins ${breakMins == 1 ? l10n.starting_min : l10n.starting_min_plural}", style: appStyle.fonts.B_14R .apply(color: appStyle.colors.textTertiary)) ], @@ -137,8 +139,14 @@ class LessonWidget extends StatelessWidget { } } -void showLessonBottomSheet(BuildContext context, Lesson lesson, int? lessonNo, - Color accent, Color secondary, Color bgColor) { +void showLessonBottomSheet( + BuildContext context, + AppLocalizations l10n, + Lesson lesson, + int? lessonNo, + Color accent, + Color secondary, + Color bgColor) { showModalBottomSheet( context: context, elevation: 100, @@ -216,7 +224,7 @@ void showLessonBottomSheet(BuildContext context, Lesson lesson, int? lessonNo, .apply(color: appStyle.colors.textPrimary), ), Text( - '${lesson.start.format(context, FormatMode.hmm)} - ${lesson.end.format(context, FormatMode.hmm)}', + '${lesson.start.format(l10n, FormatMode.hmm)} - ${lesson.end.format(l10n, FormatMode.hmm)}', style: appStyle.fonts.B_14R .apply(color: appStyle.colors.textPrimary), ), @@ -229,7 +237,7 @@ void showLessonBottomSheet(BuildContext context, Lesson lesson, int? lessonNo, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - AppLocalizations.of(context)!.lesson_subject, + l10n.lesson_subject, style: appStyle.fonts.H_14px, ), SizedBox(height: 4), diff --git a/firka/lib/ui/phone/widgets/lesson_big.dart b/firka/lib/ui/phone/widgets/lesson_big.dart index c420a7d6..1c31ece3 100644 --- a/firka/lib/ui/phone/widgets/lesson_big.dart +++ b/firka/lib/ui/phone/widgets/lesson_big.dart @@ -9,14 +9,15 @@ import '../../../helpers/api/model/timetable.dart'; import '../../widget/class_icon.dart'; class LessonBigWidget extends StatelessWidget { + final AppLocalizations l10n; final DateTime now; final int? lessonNo; final Lesson? lesson; final Lesson? prevLesson; final Lesson? nextLesson; - const LessonBigWidget( - this.now, this.lessonNo, this.lesson, this.prevLesson, this.nextLesson, + const LessonBigWidget(this.l10n, this.now, this.lessonNo, this.lesson, + this.prevLesson, this.nextLesson, {super.key}); @override @@ -40,10 +41,10 @@ class LessonBigWidget extends StatelessWidget { var secsLeft = timeLeft.inSeconds; var timeLeftStr = - "$minsLeft ${minsLeft == 1 ? AppLocalizations.of(context)!.starting_min : AppLocalizations.of(context)!.starting_min_plural}"; + "$minsLeft ${minsLeft == 1 ? l10n.starting_min : l10n.starting_min_plural}"; if (minsLeft < 1) { timeLeftStr = - "$secsLeft ${secsLeft == 1 ? AppLocalizations.of(context)!.starting_sec : AppLocalizations.of(context)!.starting_sec_plural}"; + "$secsLeft ${secsLeft == 1 ? l10n.starting_sec : l10n.starting_sec_plural}"; } return Column( @@ -101,10 +102,7 @@ class LessonBigWidget extends StatelessWidget { children: [ Row( children: [ - Text( - lesson!.start - .toLocal() - .format(context, FormatMode.hmm), + Text(lesson!.start.toLocal().format(l10n, FormatMode.hmm), style: appStyle.fonts.B_14R .apply(color: appStyle.colors.textPrimary)), Card( @@ -122,8 +120,7 @@ class LessonBigWidget extends StatelessWidget { Row( children: [ SizedBox(width: 18), - Text( - lesson!.end.toLocal().format(context, FormatMode.hmm), + Text(lesson!.end.toLocal().format(l10n, FormatMode.hmm), style: appStyle.fonts.B_12R .apply(color: appStyle.colors.textSecondary)), ], @@ -147,8 +144,7 @@ class LessonBigWidget extends StatelessWidget { duration - nextLesson!.start.difference(now).inMilliseconds; var timeLeft = nextLesson!.start.difference(now); - var timeLeftStr = - AppLocalizations.of(context)!.timeLeft(timeLeft.inMinutes + 1); + var timeLeftStr = l10n.timeLeft(timeLeft.inMinutes + 1); return Column( crossAxisAlignment: CrossAxisAlignment.center, @@ -166,11 +162,11 @@ class LessonBigWidget extends StatelessWidget { child: Padding( padding: EdgeInsets.all(4), child: FirkaIconWidget( - FirkaIconType.MajesticonsLocal, 'cupFilled', + FirkaIconType.majesticonsLocal, 'cupFilled', color: wearStyle.colors.accent, size: 24), ), ), - Text(AppLocalizations.of(context)!.breakTxt, + Text(l10n.breakTxt, style: appStyle.fonts.B_16SB .apply(color: appStyle.colors.textPrimary)), ], @@ -193,7 +189,7 @@ class LessonBigWidget extends StatelessWidget { Text( prevLesson!.end .toLocal() - .format(context, FormatMode.hmm), + .format(l10n, FormatMode.hmm), style: appStyle.fonts.B_14R .apply(color: appStyle.colors.textPrimary)), ], @@ -203,7 +199,7 @@ class LessonBigWidget extends StatelessWidget { Text( nextLesson!.start .toLocal() - .format(context, FormatMode.hmm), + .format(l10n, FormatMode.hmm), style: appStyle.fonts.B_14R .apply(color: appStyle.colors.textPrimary)), ], diff --git a/firka/lib/ui/phone/widgets/lesson_small.dart b/firka/lib/ui/phone/widgets/lesson_small.dart index e4bad7a2..28f1a6d1 100644 --- a/firka/lib/ui/phone/widgets/lesson_small.dart +++ b/firka/lib/ui/phone/widgets/lesson_small.dart @@ -1,5 +1,6 @@ import 'package:firka/helpers/extensions.dart'; import 'package:firka/helpers/ui/firka_card.dart'; +import 'package:firka/l10n/app_localizations.dart'; import 'package:firka/ui/model/style.dart'; import 'package:flutter/material.dart'; @@ -7,10 +8,12 @@ import '../../../helpers/api/model/timetable.dart'; import '../../widget/class_icon.dart'; class LessonSmallWidget extends StatelessWidget { + final AppLocalizations l10n; final Lesson lesson; final bool lessonActive; - const LessonSmallWidget(this.lesson, this.lessonActive, {super.key}); + const LessonSmallWidget(this.l10n, this.lesson, this.lessonActive, + {super.key}); @override Widget build(BuildContext context) { @@ -44,7 +47,7 @@ class LessonSmallWidget extends StatelessWidget { ), ), Text( - "${lesson.start.toLocal().format(context, FormatMode.hmm)} - ${lesson.end.toLocal().format(context, FormatMode.hmm)}", + "${lesson.start.toLocal().format(l10n, FormatMode.hmm)} - ${lesson.end.toLocal().format(l10n, FormatMode.hmm)}", style: appStyle.fonts.B_14R .apply(color: appStyle.colors.textPrimary)), ], diff --git a/firka/lib/ui/widget/class_icon.dart b/firka/lib/ui/widget/class_icon.dart index 396fe955..2f22256d 100644 --- a/firka/lib/ui/widget/class_icon.dart +++ b/firka/lib/ui/widget/class_icon.dart @@ -25,7 +25,7 @@ class ClassIconWidget extends StatelessWidget { Widget build(BuildContext context) { var iconCategory = getIconType(_uid, _className, _category); - return FirkaIconWidget(FirkaIconType.Majesticons, getIconData(iconCategory), + return FirkaIconWidget(FirkaIconType.majesticons, getIconData(iconCategory), color: color, size: size); } } diff --git a/firka/lib/ui/widget/firka_icon.dart b/firka/lib/ui/widget/firka_icon.dart index fa66125e..2034e743 100644 --- a/firka/lib/ui/widget/firka_icon.dart +++ b/firka/lib/ui/widget/firka_icon.dart @@ -5,8 +5,8 @@ import 'package:flutter_svg/svg.dart'; import 'package:majesticons_flutter/majesticons_flutter.dart'; enum FirkaIconType { - Majesticons, - MajesticonsLocal, + majesticons, + majesticonsLocal, } class FirkaIconWidget extends StatelessWidget { @@ -21,9 +21,9 @@ class FirkaIconWidget extends StatelessWidget { @override Widget build(BuildContext context) { switch (iconType) { - case FirkaIconType.Majesticons: + case FirkaIconType.majesticons: return Majesticon(iconData as Uint8List, color: color, size: size); - case FirkaIconType.MajesticonsLocal: + case FirkaIconType.majesticonsLocal: return SvgPicture.asset( 'assets/majesticons/${iconData as String}.svg', color: color,