gpt4 book ai didi

flutter TabBarView 不会通过 TabController 通过点击选项卡/选项卡而改变,滑动时不会改变,但 tabbarview 会

转载 作者:行者123 更新时间:2023-12-04 04:19:41 27 4
gpt4 key购买 nike

我一直在尝试使用标签更改应用栏标题的许多解决方案,我解决了它,但现在有一个小问题;按下选项卡时,应用栏会随选项卡而变化,但不会随选项卡 View 而变化。在选项卡栏 View 上向左或向右滑动会更改选项卡 View ,但不会更改选项卡(应用栏标题也不会更改)。

我的代码如下:

final List<Tabs> _tabs = [new Tabs(title: "Registered UAS", icon: new IconData(58826, fontFamily: 'MaterialIcons')),
new Tabs(title: "Registration", icon: IconData(57680, fontFamily: 'MaterialIcons'))
];

Tabs _myHandler ;

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 WillPopScope(
child: DefaultTabController(
length: 2,
child: new Scaffold(
appBar: AppBar(
title: Text(_myHandler.title),
bottom: new TabBar(
controller: _controller,
tabs: <Widget>[
new Tab(icon: new Icon(_tabs[0].icon)),
new Tab(icon: new Icon(_tabs[1].icon))
],
),
),
body: new TabBarView(children: [...])

我关注了 this用于在选项卡更改时更改应用栏标题,现在我遇到了类似的情况,例如 this ,除了我不认为它的解决方案对我有用(我已经尝试过了)

最佳答案

通过添加 controller: _controller, 解决了它在 TabBarView 下

关于 flutter TabBarView 不会通过 TabController 通过点击选项卡/选项卡而改变,滑动时不会改变,但 tabbarview 会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59676621/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com