Skip to content

Instantly share code, notes, and snippets.

@redbluenat
Last active February 11, 2019 08:15
Show Gist options
  • Save redbluenat/ca68d10e0516a2cbadc6060b90aba1cc to your computer and use it in GitHub Desktop.
Save redbluenat/ca68d10e0516a2cbadc6060b90aba1cc to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
@override
HomePageState createState() => HomePageState();
}
class HomePageState extends State<HomePage> {
int selectedIndex = 0;
final widgetOptions = [
Text('Beer List'),
Text('Add new beer'),
Text('Favourites'),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Beer App'),
),
body: Center(
child: widgetOptions.elementAt(selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.local_drink), title: Text('Beers')),
BottomNavigationBarItem(
icon: Icon(Icons.add_a_photo), title: Text('New Beer')),
BottomNavigationBarItem(
icon: Icon(Icons.favorite), title: Text('Favourites')),
],
currentIndex: selectedIndex,
fixedColor: Colors.deepPurple,
onTap: onItemTapped,
),
);
}
void onItemTapped(int index) {
setState(() {
selectedIndex = index;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment