Skip to content

Instantly share code, notes, and snippets.

@paulallies
Last active April 24, 2020 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulallies/c263cfd1b42312fe5eec832115e59dad to your computer and use it in GitHub Desktop.
Save paulallies/c263cfd1b42312fe5eec832115e59dad to your computer and use it in GitHub Desktop.
Nav Container
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