Want to use a TabBar and TabBarView as an in page widget? Turns out it works. This is the relevant code snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | import 'package:flutter/material.dart'; void main() { runApp(new MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Demo', home: new MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => new _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin { TabController _controller; @override void initState() { super.initState(); _controller = new TabController(length: 2, vsync: this); } @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text('TestProject'), ), body: new ListView( children: <Widget>[ new Card( child: new ListTile( title: const Text('Some information'), ), ), new Container( decoration: new BoxDecoration(color: Theme.of(context).primaryColor), child: new TabBar( controller: _controller, tabs: [ new Tab( icon: const Icon(Icons.home), text: 'Address', ), new Tab( icon: const Icon(Icons.my_location), text: 'Location', ), ], ), ), new Container( height: 80.0, child: new TabBarView( controller: _controller, children: <Widget>[ new Card( child: new ListTile( leading: const Icon(Icons.home), title: new TextField( decoration: const InputDecoration(hintText: 'Search for address...'), ), ), ), new Card( child: new ListTile( leading: const Icon(Icons.location_on), title: new Text('Latitude: 48.09342\nLongitude: 11.23403'), trailing: new IconButton(icon: const Icon(Icons.my_location), onPressed: () {}), ), ), ], ), ), new Card( child: new ListTile( title: const Text('Some more information'), ), ), new RaisedButton( color: Theme.of(context).primaryColor, onPressed: () {}, child: const Text( 'Search for POIs', style: const TextStyle(color: Colors.white), ), ), ], ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.