31 Flutter: BottomNavigationBar
main.dart
import 'package:flutter/material.dart';
void main(){
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_State createState() => new _State();
}
//State is information of the application that can change over time or when some actions are taken.
class _State extends State<MyApp>{
List<BottomNavigationBarItem> _items;
String _value = '';
int _index = 0;
@override
//initState() is the default state or something which runs before the actual state or before the setState
void initState() {
_items = new List();
_items.add(new BottomNavigationBarItem(icon: new Icon(Icons.people), title: new Text('People')));
_items.add(new BottomNavigationBarItem(icon: new Icon(Icons.weekend), title: new Text('Weekend')));
_items.add(new BottomNavigationBarItem(icon: new Icon(Icons.message), title: new Text('Message')));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Name here'),
backgroundColor: Colors.red,
),
//hit Ctrl+space in intellij to know what are the options you can use in flutter widgets
body: new Container(
padding: new EdgeInsets.all(32.0),
child: new Center(
child: new Column(
children: <Widget>[
new Text(_value)
],
),
),
),
bottomNavigationBar: new BottomNavigationBar(
items: _items,
fixedColor: Colors.blue,
currentIndex: _index,
onTap: (int item){
_index = item;
_value = "Current value is: ${_index.toString()}";
},
),
);
}
}
Last updated