@@ -19,10 +19,12 @@ class MainScreen extends StatefulWidget {
1919}
2020
2121class _MainScreenState extends State <MainScreen > {
22- int _currentPageIndex = 0 ;
22+ static const Color backgroundColor = Color ( 0xFFeaf6f5 ) ;
2323 late final PageController _pageController;
24+ int _currentPageIndex = 0 ;
25+ bool extended = false ;
2426
25- List <Widget > get _destinations => [
27+ List <NavigationDestination > get _destinations => [
2628 const NavigationDestination (
2729 icon: Icon (Icons .map),
2830 label: 'Map' ,
@@ -52,14 +54,8 @@ class _MainScreenState extends State<MainScreen> {
5254 ),
5355 label: 'Recover' ,
5456 ),
55- NavigationDestination (
56- icon: Row (
57- mainAxisSize: MainAxisSize .min,
58- children: const [
59- Icon (Icons .settings),
60- Icon (Icons .info),
61- ],
62- ),
57+ const NavigationDestination (
58+ icon: Icon (Icons .settings),
6359 label: 'Settings' ,
6460 ),
6561 ];
@@ -100,19 +96,74 @@ class _MainScreenState extends State<MainScreen> {
10096 @override
10197 Widget build (BuildContext context) => FMTCBackgroundDownload (
10298 child: Scaffold (
103- backgroundColor: Colors .white,
104- bottomNavigationBar: NavigationBar (
105- onDestinationSelected: _onDestinationSelected,
106- selectedIndex: _currentPageIndex,
107- destinations: _destinations,
108- labelBehavior: MediaQuery .of (context).size.width > 450
109- ? null
110- : NavigationDestinationLabelBehavior .onlyShowSelected,
111- ),
112- body: PageView (
113- controller: _pageController,
114- physics: const NeverScrollableScrollPhysics (),
115- children: _pages,
99+ backgroundColor: backgroundColor,
100+ bottomNavigationBar: MediaQuery .of (context).size.width > 950
101+ ? null
102+ : NavigationBar (
103+ backgroundColor:
104+ Theme .of (context).navigationBarTheme.backgroundColor,
105+ onDestinationSelected: _onDestinationSelected,
106+ selectedIndex: _currentPageIndex,
107+ destinations: _destinations,
108+ labelBehavior: MediaQuery .of (context).size.width > 450
109+ ? null
110+ : NavigationDestinationLabelBehavior .onlyShowSelected,
111+ ),
112+ body: Row (
113+ children: [
114+ if (MediaQuery .of (context).size.width > 950 )
115+ NavigationRail (
116+ onDestinationSelected: _onDestinationSelected,
117+ selectedIndex: _currentPageIndex,
118+ groupAlignment: 0 ,
119+ extended: extended,
120+ backgroundColor: backgroundColor,
121+ destinations: _destinations
122+ .map (
123+ (d) => NavigationRailDestination (
124+ icon: d.icon,
125+ label: Text (d.label),
126+ padding: const EdgeInsets .all (10 ),
127+ ),
128+ )
129+ .toList (),
130+ leading: Row (
131+ children: [
132+ AnimatedContainer (
133+ width: extended ? 205 : 0 ,
134+ duration: kThemeAnimationDuration,
135+ curve: Curves .easeInOut,
136+ ),
137+ IconButton (
138+ icon: AnimatedSwitcher (
139+ duration: kThemeAnimationDuration,
140+ switchInCurve: Curves .easeInOut,
141+ switchOutCurve: Curves .easeInOut,
142+ child: Icon (
143+ extended ? Icons .menu_open : Icons .menu,
144+ key: UniqueKey (),
145+ ),
146+ ),
147+ onPressed: () => setState (() => extended = ! extended),
148+ tooltip: ! extended ? 'Extend Menu' : 'Collapse Menu' ,
149+ ),
150+ ],
151+ ),
152+ ),
153+ Expanded (
154+ child: ClipRRect (
155+ borderRadius: const BorderRadius .only (
156+ topLeft: Radius .circular (16 ),
157+ bottomLeft: Radius .circular (16 ),
158+ ),
159+ child: PageView (
160+ controller: _pageController,
161+ physics: const NeverScrollableScrollPhysics (),
162+ children: _pages,
163+ ),
164+ ),
165+ ),
166+ ],
116167 ),
117168 ),
118169 );
0 commit comments