Flutter change main appbar title on other pages. You can add a TabController and add listen to it such that you call setState whenever you are switching between the Tabs, and change the AppBar title accordingly.
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 |
import "package:flutter/material.dart"; void main(){ runApp(new MaterialApp(home:new MyApp(), )); } class MyApp extends StatefulWidget { @override _MyAppState createState() => new _MyAppState(); } class _MyAppState extends State<MyApp> with TickerProviderStateMixin{ final List<MyTabs> _tabs = [new MyTabs(title: "Teal",color: Colors.teal[200]), new MyTabs(title: "Orange",color: Colors.orange[200]) ]; MyTabs _myHandler ; TabController _controller ; void initState() { super.initState(); _controller = new TabController(length: 2, vsync: this); _myHandler = _tabs[0]; _controller.addListener(_handleSelected); } void _handleSelected() { setState(() { _myHandler= _tabs[_controller.index]; }); } @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar(title: new Text(_myHandler.title), backgroundColor: _myHandler.color, bottom: new TabBar( controller: _controller, tabs: <Tab>[ new Tab(text: _tabs[0].title,), new Tab(text: _tabs[1].title,) ], ),), ); } } class MyTabs { final String title; final Color color; MyTabs({this.title,this.color}); } |
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.