-
-
Notifications
You must be signed in to change notification settings - Fork 362
Expand file tree
/
Copy pathresponsive_navbar.dart
More file actions
130 lines (113 loc) · 3.66 KB
/
Copy pathresponsive_navbar.dart
File metadata and controls
130 lines (113 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:path_to_regexp/path_to_regexp.dart';
import 'package:saber/components/canvas/save_indicator.dart';
import 'package:saber/components/navbar/horizontal_navbar.dart';
import 'package:saber/components/navbar/vertical_navbar.dart';
import 'package:saber/data/prefs.dart';
import 'package:saber/data/routes.dart';
import 'package:saber/pages/home/home.dart';
import 'package:saber/pages/home/whiteboard.dart';
class ResponsiveNavbar extends StatefulWidget {
const ResponsiveNavbar({
super.key,
required this.body,
this.selectedIndex = 0,
});
final Widget body;
final int selectedIndex;
@override
State<ResponsiveNavbar> createState() => _ResponsiveNavbarState();
static bool isLargeScreen = true;
static void setAndroidNavBarColor(ThemeData theme) async {
await null;
final brightness = theme.brightness;
final otherBrightness =
brightness == Brightness.dark ? Brightness.light : Brightness.dark;
final overlayStyle = brightness == Brightness.dark
? SystemUiOverlayStyle.dark
: SystemUiOverlayStyle.light;
SystemChrome.setSystemUIOverlayStyle(overlayStyle.copyWith(
systemNavigationBarColor: Colors.transparent,
systemNavigationBarIconBrightness: otherBrightness,
));
}
}
class _ResponsiveNavbarState extends State<ResponsiveNavbar> {
@override
void initState() {
Prefs.locale.addListener(onChange);
Prefs.layoutSize.addListener(onChange);
super.initState();
}
void onChange() {
setState(() {});
}
void onDestinationSelected(int index) {
if (index == widget.selectedIndex) return;
// if on whiteboard, check if saved
final whiteboardPath = pathToFunction(RoutePaths.home)(
{'subpage': HomePage.whiteboardSubpage});
if (HomeRoutes.getRoute(widget.selectedIndex) == whiteboardPath) {
final savingState = Whiteboard.savingState;
switch (savingState) {
case null:
case SavingState.savedWithoutThumbnail:
case SavingState.savedWithThumbnail:
break;
case SavingState.waitingToSave:
Whiteboard.triggerSave();
return;
case SavingState.saving:
return;
}
}
context.go(HomeRoutes.getRoute(index));
}
@override
Widget build(BuildContext context) {
ResponsiveNavbar.isLargeScreen = switch (Prefs.layoutSize.value) {
LayoutSize.auto => MediaQuery.sizeOf(context).width >= 600,
LayoutSize.phone => false,
LayoutSize.tablet => true,
};
ResponsiveNavbar.setAndroidNavBarColor(Theme.of(context));
if (ResponsiveNavbar.isLargeScreen) {
return Scaffold(
body: Row(children: [
IntrinsicWidth(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 300),
child: VerticalNavbar(
destinations: HomeRoutes.navigationRailDestinations,
selectedIndex: widget.selectedIndex,
onDestinationSelected: onDestinationSelected,
),
),
),
Expanded(child: widget.body),
]),
);
} // else mobile
return Scaffold(
body: widget.body,
bottomNavigationBar: HorizontalNavbar(
destinations: HomeRoutes.navigationDestinations,
selectedIndex: widget.selectedIndex,
onDestinationSelected: onDestinationSelected,
),
);
}
@override
void dispose() {
Prefs.locale.removeListener(onChange);
Prefs.layoutSize.removeListener(onChange);
super.dispose();
}
}
enum LayoutSize {
auto,
phone,
tablet,
}