class _MyHomePageState extends State<MyHomePage> { static var _message = "ok."; static var _stars = '★★★★★'; static var _star = 0; @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text('App Name'), leading: BackButton( color: Colors.white, ), actions: <Widget>[ IconButton( icon: Icon(Icons.android), tooltip: 'add star...', onPressed: iconPressedA, ), IconButton( icon: Icon(Icons.favorite), tooltip: 'subtract star...', onPressed: iconPressedB, ) ], bottom: PreferredSize( preferredSize: const Size.fromHeight(30.0), child: Center( child: Text(_stars, style: TextStyle( fontSize: 22.0, color:Colors.white, ),), ), ), ), body: new Center( child: Text( _message, style: const TextStyle( fontSize: 28.0, ), ) ), ); } void iconPressedA(){ _message = 'tap "Android".'; _star++; update(); } void iconPressedB(){ _message = 'tap "favorite".'; _star--; update(); } void update(){ _star = _star < 0 ? 0 : _star > 5 ? 5 : _star; setState((){ _stars = '★★★★★☆☆☆☆☆'.substring(5 - _star, 5 - _star + 5); _message = _message + '[$_star]'; }); } }
BottomNavigationBar
class _MyHomePageState extends State<MyHomePage> { static var _message = "ok."; static var _index = 0; @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text('App Name'), ), body: new Center( child: Text( _message, style: const TextStyle( fontSize: 28.0, ), ), ), bottomNavigationBar: BottomNavigationBar( currentIndex: _index, backgroundColor: Colors.lightBlueAccent, items: <BottomNavigationBarItem>[ BottomNavigationBarItem( label: 'Android', icon: Icon(Icons.android, color: Colors.black, size: 50), ), BottomNavigationBarItem( label: 'Favorite', icon: Icon(Icons.android, color: Colors.red, size: 50), ), BottomNavigationBarItem( label: 'Home', icon: Icon(Icons.android, color: Colors.white, size: 50), ), ], onTap: tapBottomIcon, ), ); } void tapBottomIcon(int value) { var items = ['Android', 'Heart', 'Home']; setState((){ _index = value; _message = 'you tapped: "' + items[_index] + '".'; }); } }
List View