Skip to content

Instantly share code, notes, and snippets.

@mehmetf
Created September 3, 2017 03:18
Show Gist options
  • Save mehmetf/32dcf8e58e7655e1fa8e9a0fe5c25fe2 to your computer and use it in GitHub Desktop.
Save mehmetf/32dcf8e58e7655e1fa8e9a0fe5c25fe2 to your computer and use it in GitHub Desktop.
Navigation Builder Pattern
/// Platform agnostic navigation definition.
class NavigationItem {
final Icon icon;
final String title;
final VoidCallback onTap;
NavigationItem({this.icon, this.title, this.onTap});
}
/// Helper for returning platform specific navigation items.
class NavigationMenu {
final List<NavigationItem> items;
NavigationMenu({this.items});
Drawer get drawer {
if (!Platform.isAndroid) {
return null;
}
return new Drawer(
child: new ListView(
children: items
.map((item) => new ListTile(
leading: item.icon,
title: new Text(item.title),
onTap: item.onTap,
))
.toList()),
);
}
BottomNavigationBar get bottomBar {
if (!Platform.isIOS) {
return null;
}
return new BottomNavigationBar(
items: items
.map((item) => new BottomNavigationBarItem(
icon: item.icon,
title: new Text(item.title),
))
.toList(),
onTap: (idx) => items[idx].onTap(),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment