Created
June 8, 2017 00:16
-
-
Save HansMuller/88abe25c0c1e0d9f8ae61349c9bb59ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class TabsDemo extends StatefulWidget { | |
TabsDemo({Key key}) : super(key: key); | |
@override | |
_TabsDemoState createState() => new _TabsDemoState(); | |
} | |
class _TabsDemoState extends State<TabsDemo> with TickerProviderStateMixin { | |
static const List<int> colorShades = const <int>[200, 300, 400, 500, 600, 700]; | |
MaterialColor _activeColors = Colors.red; | |
TabController tabController; | |
@override | |
void initState() { | |
super.initState(); | |
tabController = new TabController(initialIndex: 0, length: colorShades.length, vsync: this); | |
} | |
@override | |
void dispose() { | |
tabController.dispose(); | |
super.dispose(); | |
} | |
_red() { | |
setState(() { | |
_activeColors = Colors.red; | |
}); | |
} | |
_green() { | |
setState(() { | |
_activeColors = Colors.green; | |
}); | |
} | |
_blue() { | |
setState(() { | |
_activeColors = Colors.blue; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text('Flutter Demo'), | |
bottom: new TabBar( | |
controller: tabController, | |
tabs: colorShades.map((int shade) { | |
return new Container( | |
color: _activeColors.shade600, | |
child: new Tab(text: shade.toString()), | |
); | |
}).toList(), | |
), | |
), | |
body: new Column( | |
children: <Widget>[ | |
new Expanded( | |
child: new TabBarView( | |
controller: tabController, | |
children: colorShades.map((int shade) { | |
return new Center( | |
child: new Container( | |
width: 50.0, | |
height: 50.0, | |
color: _activeColors[shade], | |
), | |
); | |
}).toList(), | |
), | |
), | |
new Divider(), | |
new ButtonBar( | |
children: <Widget>[ | |
new RaisedButton(child: new Text('red'), onPressed: _red), | |
new RaisedButton(child: new Text('green'), onPressed: _green), | |
new RaisedButton(child: new Text('blue'), onPressed: _blue), | |
], | |
), | |
], | |
), | |
); | |
} | |
} | |
void main() { | |
runApp(new MaterialApp(home: new TabsDemo())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment