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

Wei*_*ong 5 tabs flutter flutter-appbar

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

我的代码如下:

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: [...])
Run Code Online (Sandbox Code Playgroud)

我按照此方法更改了选项卡更改上的应用程序栏标题,现在我陷入了类似的情况除了我认为它的解决方案不适合我(我已经尝试过)

Wei*_*ong 4

通过controller: _controller,在TabBarView下添加解决了这个问题