Last active
December 2, 2016 18:23
-
-
Save gavindoughtie/264e2ba1e2cbb960f4996073abc3a753 to your computer and use it in GitHub Desktop.
2-level tab bar error minimal case
This file contains hidden or 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'; | |
void main() { | |
runApp( | |
new MaterialApp( | |
title: 'Flutter Demo', | |
theme: new ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: new FlutterDemo(), | |
), | |
); | |
} | |
class FlutterDemo extends StatefulWidget { | |
FlutterDemo({Key key}) : super(key: key); | |
@override | |
_FlutterDemoState createState() => new _FlutterDemoState(); | |
} | |
class _FlutterDemoState extends State<FlutterDemo> { | |
Map<int, Color> _activeColors = Colors.red; | |
Widget _makeTabBar(BuildContext context) { | |
final steps = [200, 300, 400, 500, 600, 700]; | |
final colorSteps = steps.map((step) => _activeColors[step]).toList(); | |
final colorWidgets = colorSteps.map((color) { | |
return new Container( | |
width: 50.0, | |
height: 50.0, | |
decoration: new BoxDecoration(backgroundColor: color)); | |
}).toList(growable: false); | |
final tbs = new TabBarSelection<Color>( | |
child: new TabBarView<Color>(children: colorWidgets), | |
values: colorSteps, | |
value: colorSteps[0]); | |
return tbs; | |
} | |
_red() { | |
setState(() { | |
_activeColors = Colors.red; | |
}); | |
} | |
_green() { | |
setState(() { | |
_activeColors = Colors.green; | |
}); | |
} | |
_blue() { | |
setState(() { | |
_activeColors = Colors.blue; | |
}); | |
} | |
Widget _makeButtons() { | |
final red = new FlatButton(child: new Text('red'), onPressed: _red); | |
final green = new FlatButton(child: new Text('green'), onPressed: _green); | |
final blue = new FlatButton(child: new Text('blue'), onPressed: _blue); | |
return new ButtonBar(children: [red, green, blue]); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text('Flutter Demo'), | |
), | |
body: new Column(children: [ | |
_makeButtons(), | |
new Container(height: 200.0, child: _makeTabBar(context)) | |
]), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment