feat(nav): open pages kept in több over the whole screen

This commit is contained in:
zypherift
2026-12-06 21:27:03 +01:00
parent 9e899b458e
commit f258255202
7 changed files with 88 additions and 34 deletions

View File

@@ -31,6 +31,7 @@ import 'package:firka/ui/phone/screens/themes/user_theme.dart';
import 'package:firka/routing/chart_interaction_scope.dart';
import 'package:firka/routing/shell_with_nav_bar.dart';
import 'package:firka/routing/swipable_navigator_container.dart';
import 'package:firka/ui/theme/style.dart';
import 'package:go_router/go_router.dart';
GoRouter createAppRouter() {
@@ -154,6 +155,24 @@ GoRouter createAppRouter() {
child: MessagesScreen(initData, key: state.pageKey),
),
),
// A main page kept in "Több" opens over the whole screen
GoRoute(
path: '/more/:page',
builder: (context, state) => DefaultAssetBundle(
bundle: FirkaBundle(),
child: Scaffold(
backgroundColor: appStyle.colors.background,
body: SafeArea(
child: switch (state.pathParameters['page']) {
'grades' => HomeGradesScreen(initData, pushed: true),
'timetable' => HomeTimetableScreen(initData, pushed: true),
'absences' => HomeOmissionsScreen(initData, pushed: true),
_ => HomeMainScreen(initData, pushed: true),
},
),
),
),
),
GoRoute(
path: '/subjects',
builder: (context, state) => DefaultAssetBundle(

View File

@@ -8,9 +8,8 @@ import 'package:flutter/foundation.dart';
enum NavItem { home, grades, timetable, absences, messages, account, settings }
extension NavItemBranch on NavItem {
/// The shell branch of the page. Messages, account and settings are only
/// opened as a tab from the bar, from "Több" they are pushed with a back
/// header.
/// The shell branch of the page while it is in the bar. From "Több"
/// every page is pushed over the whole screen with a back header.
int get branch => switch (this) {
NavItem.home => 0,
NavItem.grades => 1,
@@ -20,8 +19,6 @@ extension NavItemBranch on NavItem {
NavItem.account => 5,
NavItem.settings => 6,
};
bool get alwaysTab => branch < 4;
}
/// Which pages are in the bar and which in "Több", in order, and the "Több"

View File

@@ -56,6 +56,18 @@ class _ShellWithNavBarState extends State<ShellWithNavBar> {
StatefulNavigationShell get _shell => widget.navigationShell;
@override
void initState() {
super.initState();
// The app opens on home, which may have been moved to "Több"
WidgetsBinding.instance.addPostFrameCallback((_) {
final bar = navLayout.value.bar;
if (mounted && !bar.any((i) => i.branch == _shell.currentIndex)) {
_shell.goBranch(bar.first.branch);
}
});
}
void _setPanel(bool open) {
setState(() {
_panelOpen = open;
@@ -65,14 +77,16 @@ class _ShellWithNavBarState extends State<ShellWithNavBar> {
void _open(NavItem item) {
_setPanel(false);
if (item.alwaysTab || navLayout.value.bar.contains(item)) {
if (navLayout.value.bar.contains(item)) {
if (_shell.currentIndex != item.branch) _shell.goBranch(item.branch);
return;
}
// From "Több" every page opens over the whole screen with a back header
context.push(switch (item) {
NavItem.messages => '/messages',
NavItem.account => '/account',
_ => '/settings',
NavItem.settings => '/settings',
_ => '/more/${item.name}',
});
}
@@ -86,13 +100,13 @@ class _ShellWithNavBarState extends State<ShellWithNavBar> {
final preview = _preview;
if (preview == null) return;
saveNavLayout(preview);
// A tab-only page taken out of the bar while open has no back header,
// so the user is taken home
// A page taken out of the bar is no longer a tab, so the user goes
// to the first one
final current = NavItem.values.firstWhere(
(i) => i.branch == _shell.currentIndex,
);
if (!current.alwaysTab && !preview.bar.contains(current)) {
_shell.goBranch(NavItem.home.branch);
if (!preview.bar.contains(current)) {
_shell.goBranch(preview.bar.first.branch);
}
},
onEnd: () => setState(() => _preview = null),

View File

@@ -4,6 +4,7 @@ import 'package:isar_community/isar.dart';
import 'package:firka_common/ui/components/firka_card.dart';
import 'package:firka_common/core/grade_helper.dart';
import 'package:firka_common/core/subject_overrides.dart';
import 'package:firka/ui/shared/back_header.dart';
import 'package:firka/ui/phone/widgets/grade_chart.dart';
import 'package:firka/ui/phone/widgets/grade_summary_bar.dart';
import 'package:firka/ui/shared/grade_small_card.dart';
@@ -20,7 +21,10 @@ import 'package:firka/ui/theme/style.dart';
class HomeGradesScreen extends StatefulWidget {
final AppInitialization data;
const HomeGradesScreen(this.data, {super.key});
/// Opened from "Több" over the whole screen, with a back header
final bool pushed;
const HomeGradesScreen(this.data, {this.pushed = false, super.key});
@override
State<StatefulWidget> createState() => _HomeGradesScreen();
@@ -120,16 +124,19 @@ class _HomeGradesScreen extends FirkaState<HomeGradesScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
headingText(widget.data.l10n.subjects),
style: appStyle.fonts.H_H2.apply(
color: appStyle.colors.textPrimary,
if (widget.pushed)
BackHeader(widget.data.l10n.subjects)
else
Row(
children: [
Text(
headingText(widget.data.l10n.subjects),
style: appStyle.fonts.H_H2.apply(
color: appStyle.colors.textPrimary,
),
),
),
],
),
],
),
SizedBox(height: 24),
GradeChartWithInteraction(grades: allGrades),
SizedBox(height: 10),

View File

@@ -1,6 +1,7 @@
import 'package:firka_common/data/last_seen.dart';
import 'package:firka_common/data/models/grade_cache_model.dart';
import 'package:firka_common/data/models/lesson_cache_model.dart';
import 'package:firka/ui/shared/back_header.dart';
import 'package:firka/core/last_seen_helper.dart';
import 'package:firka/core/settings/settings_repository.dart';
import 'package:firka/core/settings/settings_schema.dart';
@@ -25,7 +26,10 @@ import '../../widgets/home_main_welcome.dart';
class HomeMainScreen extends StatefulWidget {
final AppInitialization data;
const HomeMainScreen(this.data, {super.key});
/// Opened from "Több" over the whole screen, with a back header
final bool pushed;
const HomeMainScreen(this.data, {this.pushed = false, super.key});
@override
State<HomeMainScreen> createState() => _HomeMainScreen();
@@ -207,6 +211,7 @@ class _HomeMainScreen extends FirkaState<HomeMainScreen> {
clipBehavior: Clip.none,
children: [
SizedBox(height: 24),
if (widget.pushed) BackHeader(widget.data.l10n.home),
_FadeInWhenLoaded(
loaded: student != null,
child: student != null

View File

@@ -26,7 +26,10 @@ import 'package:firka_common/core/subject_overrides.dart';
class HomeOmissionsScreen extends StatefulWidget {
final AppInitialization data;
const HomeOmissionsScreen(this.data, {super.key});
/// Opened from "Több" over the whole screen, with a back header
final bool pushed;
const HomeOmissionsScreen(this.data, {this.pushed = false, super.key});
@override
State<StatefulWidget> createState() => _HomeOmissionsScreen();
@@ -105,11 +108,13 @@ class _HomeOmissionsScreen extends FirkaState<HomeOmissionsScreen> {
// From "Több" the header leads back home, in the bar it is a tab
ValueListenableBuilder(
valueListenable: navLayout,
builder: (context, layout, _) => BackHeader(
widget.data.l10n.omissions,
back: !layout.bar.contains(NavItem.absences),
onTap: () => context.go('/home'),
),
builder: (context, layout, _) => widget.pushed
? BackHeader(widget.data.l10n.omissions)
: BackHeader(
widget.data.l10n.omissions,
back: !layout.bar.contains(NavItem.absences),
onTap: () => context.go('/home'),
),
),
SizedBox(height: 20),
SingleChildScrollView(

View File

@@ -1,3 +1,4 @@
import 'package:firka/ui/shared/back_header.dart';
import 'package:firka/ui/phone/widgets/tt_header.dart';
import 'package:firka/ui/phone/widgets/tt_add_sheet.dart';
import 'package:firka/core/day_notes.dart';
@@ -31,7 +32,10 @@ import 'package:firka/ui/shared/firka_icon.dart';
class HomeTimetableScreen extends StatefulWidget {
final AppInitialization data;
const HomeTimetableScreen(this.data, {super.key});
/// Opened from "Több" over the whole screen, with a back header
final bool pushed;
const HomeTimetableScreen(this.data, {this.pushed = false, super.key});
@override
State<HomeTimetableScreen> createState() => _HomeTimetableScreen();
@@ -428,12 +432,15 @@ class _HomeTimetableScreen extends FirkaState<HomeTimetableScreen>
children: [
TtHeaderRow(
children: [
Text(
headingText(widget.data.l10n.timetable),
style: appStyle.fonts.H_H2.apply(
color: appStyle.colors.textPrimary,
if (widget.pushed)
BackHeader(widget.data.l10n.timetable)
else
Text(
headingText(widget.data.l10n.timetable),
style: appStyle.fonts.H_H2.apply(
color: appStyle.colors.textPrimary,
),
),
),
Row(
spacing: 8,
children: [