Last active
April 24, 2020 07:37
-
-
Save paulallies/c263cfd1b42312fe5eec832115e59dad to your computer and use it in GitHub Desktop.
Nav Container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:navexample/screen.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class NavObject { | |
Widget screen; | |
Icon navIcon; | |
Text title; | |
NavObject({this.screen, this.navIcon, this.title}); | |
} | |
List<NavObject> navItems = [ | |
NavObject( | |
screen: Screen(title: "Home"), | |
navIcon: Icon(Icons.home), | |
title: Text('Home'), | |
), | |
NavObject( | |
screen: Screen(title: "Settings"), | |
navIcon: Icon(Icons.settings), | |
title: Text('Settings'), | |
), | |
NavObject( | |
screen: Screen(title: "Share"), | |
navIcon: Icon(Icons.share), | |
title: Text('Share'), | |
), | |
]; | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
int _screenNumber = 0; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: navItems[_screenNumber].screen, | |
bottomNavigationBar: BottomNavigationBar( | |
type: BottomNavigationBarType.fixed, | |
items: navItems | |
.map((navItem) => BottomNavigationBarItem( | |
icon: navItem.navIcon, | |
title: navItem.title, | |
)) | |
.toList(), | |
currentIndex: _screenNumber, | |
onTap: (i) => setState(() { | |
_screenNumber = i; | |
}), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment