以前的答案都没有为我解决。
切换选项卡时使页面保持活动状态的解决方案是将页面包装在 IndexedStack中 。
class Tabbar extends StatefulWidget { Tabbar({this.screens}); static const Tag = "Tabbar"; final List<Widget> screens; @override State<StatefulWidget> createState() { return _TabbarState(); }}class _TabbarState extends State<Tabbar> { int _currentIndex = 0; Widget currentScreen; @override Widget build(BuildContext context) { var _l10n = PackedLocalizations.of(context); return Scaffold( body: IndexedStack( index: _currentIndex, children: widget.screens, ), bottomNavigationBar: BottomNavigationBar( fixedColor: Colors.black, type: BottomNavigationBarType.fixed, onTap: onTabTapped, currentIndex: _currentIndex, items: [ BottomNavigationBarItem( icon: new Icon(Icons.format_list_bulleted), title: new Text(_l10n.tripsTitle), ), BottomNavigationBarItem( icon: new Icon(Icons.settings), title: new Text(_l10n.settingsTitle), ) ], ),); } void onTabTapped(int index) { setState(() { _currentIndex = index; }); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)