Skip to content

Instantly share code, notes, and snippets.

@mehmetf
Created September 3, 2017 04:06
Show Gist options
  • Save mehmetf/6ccbe3cd9743e22055770511bb22c529 to your computer and use it in GitHub Desktop.
Save mehmetf/6ccbe3cd9743e22055770511bb22c529 to your computer and use it in GitHub Desktop.
class ScaffoldWithNavigation extends StatelessWidget {
final List<NavigationItem> navItems;
final NavigationItem selectedItem;
final AppBar appbar;
final Widget body;
final FloatingActionButton button;
ScaffoldWithNavigation({
this.appbar,
this.navItems,
this.selectedItem,
this.body,
this.button,
});
@override
Widget build(BuildContext context) {
Widget drawer, bottomBar;
if (Platform.isAndroid) {
drawer = new Drawer(
child: new ListView(
children: navItems.map((item) {
return new ListTile(
selected: item == selectedItem,
leading: item.icon,
title: new Text(item.title),
onTap: () {
Navigator.pop(context);
item.onTap();
});
}).toList()));
}
if (Platform.isIOS) {
bottomBar = new BottomNavigationBar(
items: navItems
.map((item) => new BottomNavigationBarItem(
icon: item.icon, title: new Text(item.title)))
.toList(),
onTap: (idx) => navItems[idx].onTap(),
currentIndex: navItems.indexOf(selectedItem),
);
}
return new Scaffold(
appBar: appbar,
bottomNavigationBar: bottomBar,
drawer: drawer,
body: body,
floatingActionButton: button,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment