-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp_scaffold.dart
80 lines (74 loc) · 2.27 KB
/
app_scaffold.dart
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
import 'package:flutter/material.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
import 'package:flutter_adaptive_scaffold_example/nav_destinations.dart';
import 'package:go_router/go_router.dart';
class AppScaffold extends StatelessWidget {
final Widget body;
final Widget? secondaryBody;
const AppScaffold({
Key? key,
required this.body,
this.secondaryBody,
}) : super(key: key ?? const ValueKey('ScaffoldWithNestedNavigation'));
@override
Widget build(BuildContext context) {
return AdaptiveLayout(
body: SlotLayout(
config: <Breakpoint, SlotLayoutConfig>{
Breakpoints.small: SlotLayout.from(
key: const Key('Body Small'),
builder: (_) => secondaryBody != null ? secondaryBody! : body,
),
Breakpoints.mediumAndUp: SlotLayout.from(
key: const Key('Body Medium'),
builder: (_) => body,
)
},
),
secondaryBody: SlotLayout(
config: <Breakpoint, SlotLayoutConfig>{
Breakpoints.small: SlotLayout.from(
key: const Key('Body Small'),
builder: null,
),
Breakpoints.mediumAndUp: SlotLayout.from(
key: const Key('Body Medium'),
builder: secondaryBody != null
? (_) => secondaryBody!
: AdaptiveScaffold.emptyBuilder,
)
},
),
);
}
}
class AppScaffoldShell extends StatelessWidget {
final StatefulNavigationShell navigationShell;
const AppScaffoldShell({
Key? key,
required this.navigationShell,
}) : super(key: key ?? const ValueKey('ScaffoldWithNestedNavigation'));
@override
Widget build(BuildContext context) {
return AdaptiveScaffold(
useDrawer: false,
selectedIndex: navigationShell.currentIndex,
onSelectedIndexChange: onNavigationEvent,
destinations: NavDestination.values
.map(
(e) => NavigationDestination(
icon: Icon(e.icon),
label: e.label,
),
)
.toList(),
body: (_) => navigationShell,
);
}
void onNavigationEvent(int index) {
navigationShell.goBranch(
index,
initialLocation: index == navigationShell.currentIndex,
);
}
}