Created
December 5, 2016 21:48
-
-
Save gavindoughtie/7c3cdfe2585ae0914189ea925b4983ff to your computer and use it in GitHub Desktop.
Workaround Example for https://github.com/flutter/flutter/issues/7135
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'; | |
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; | |
int _selKey; | |
@override | |
initState() { | |
super.initState(); | |
_selKey = 1; | |
} | |
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>( | |
key: new Key('${_selKey++}'), | |
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