Flutter 是否可以在颤振时更改选项卡栏选择中的应用程序栏文本更改?
我想更改每个选项卡栏选择的应用程序栏文本。 例: 当我单击设计器选项卡时,我希望应用程序栏文本的文本更改为designer,而当选择下一个选项卡(例如,选择了painter)时,应用程序栏文本应更改为painterFlutter 是否可以在颤振时更改选项卡栏选择中的应用程序栏文本更改?,flutter,dart,Flutter,Dart,我想更改每个选项卡栏选择的应用程序栏文本。 例: 当我单击设计器选项卡时,我希望应用程序栏文本的文本更改为designer,而当选择下一个选项卡(例如,选择了painter)时,应用程序栏文本应更改为painter 这可能吗?使用TabController收听。然后在选项卡之间切换时调用setState,并相应地更改AppBar标题 [![在此处输入图像描述][1][1] import "package:flutter/material.dart"; void main(){ runApp
这可能吗?使用
TabController
收听。然后在选项卡之间切换时调用setState,并相应地更改AppBar标题
[![在此处输入图像描述][1][1]
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: "BLABLABLA",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[2].title,)
],
),),
);
}
}
class MyTabs {
final String title;
final Color color;
MyTabs({this.title,this.color});
}```
导入“包装:颤振/材料.省道”;
void main(){
runApp(新材料应用)(主页:new MyApp(),
));
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>new_MyAppState();
}
类MyAppState使用TickerProviderStateMixin扩展状态{
最终列表_tabs=[新MyTabs(标题:“blabla”,颜色:Colors.teal[200]),
新MyTab(标题:“橙色”,颜色:Colors.Orange[200])
];
我的标签(myHandler),;
TabController\u控制器;
void initState(){
super.initState();
_控制器=新的TabController(长度:2,vsync:this);
_myHandler=_制表符[0];
_controller.addListener(_handleSelected);
}
void_handleSelected(){
设置状态(){
_myHandler=_tabs[_controller.index];
});
}
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:newappbar(标题:newtext(_myHandler.title),
背景颜色:_myHandler.color,
底部:新选项卡栏(
控制器:_控制器,
选项卡:[
新选项卡(文本:\选项卡[0]。标题,),
新选项卡(文本:\选项卡[2]。标题,)
],
),),
);
}
}
类MyTabs{
最后的字符串标题;
最终颜色;
MyTabs({this.title,this.color});
}```