-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy path47.flutter_navigation_rail_example.dart
95 lines (84 loc) · 2.88 KB
/
47.flutter_navigation_rail_example.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import 'package:flutter/material.dart';
import 'package:ig_posts/season_2/63.transperant_design_pattern.dart';
import 'package:ig_posts/utils/colors.dart';
import 'package:provider/provider.dart';
class NavigationRailNotifier extends ChangeNotifier {
int selectedIndex = 0;
setNewIndex({required int value}) {
selectedIndex = value;
notifyListeners();
}
}
class FlutterNavigationRailView extends StatelessWidget {
const FlutterNavigationRailView({super.key});
@override
Widget build(BuildContext context) {
NavigationRailNotifier navigationRailNotifier({required bool renderUI}) =>
Provider.of<NavigationRailNotifier>(context, listen: renderUI);
renderRailItem(
{required IconData defIcon,
required IconData selectedIcon,
required String label}) {
return NavigationRailDestination(
icon: Icon(defIcon, color: KConstantColors.whiteColor),
selectedIcon: Icon(
selectedIcon,
color: KConstantColors.blueColor,
),
label: Text(label));
}
renderHomeView() {
int selectedIndex = navigationRailNotifier(renderUI: true).selectedIndex;
buildContent({required String value}) {
return Text("Render $value",
style: KConstantTextstyles.bold(fontSize: 28));
}
switch (selectedIndex) {
case 0:
{
return buildContent(value: "Home View");
}
case 1:
{
return buildContent(value: "Profile View");
}
default:
{
return buildContent(value: "Settings View");
}
}
}
return Scaffold(
backgroundColor: KConstantColors.bgColor,
appBar: CustomAppBar(title: "Navigation Rail"),
body: Row(
children: [
NavigationRail(
backgroundColor: KConstantColors.bgColor,
destinations: <NavigationRailDestination>[
renderRailItem(
defIcon: Icons.home,
selectedIcon: Icons.home_filled,
label: "Home"),
renderRailItem(
defIcon: Icons.person_2_outlined,
selectedIcon: Icons.person,
label: "Home"),
renderRailItem(
defIcon: Icons.settings,
selectedIcon: Icons.settings,
label: "Home"),
],
onDestinationSelected: (val) {
navigationRailNotifier(renderUI: false)
.setNewIndex(value: val);
},
selectedIndex:
navigationRailNotifier(renderUI: true).selectedIndex),
VerticalDivider(color: KConstantColors.whiteColor),
SizedBox(width: 30),
renderHomeView()
],
));
}
}