颤动底部导航,其中一个页面有选项卡

问题描述 投票:0回答:2

我想创建一个带有底部导航栏的脚手架,以及一个始终显示当前页面标题的应用栏。当我更改底栏选项时,内容会发生明显变化。使用经典的NavigationBar结构,这一切都很好。但问题开始时,内容页面上应该有选项卡。我在父母Scaffold中创建了我的appbar。反正有没有向父窗口小部件appBar添加标签?

我的应用栏+底部导航栏页面:

class MainPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MainPageState();
  }
}
class _MainPageState extends State<MainPage> {

  int _currentPageIndex;
  List<Widget> _pages = List();

  Widget _getCurrentPage() => _pages[_currentPageIndex];

  @override
  void initState() {
    setState(() {
      _currentPageIndex = 0;

      _pages.add(BlocProvider(bloc: AgendaBloc(), child: AgendaPage()));
      _pages.add(SpeakersPage());
      _pages.add(MenuPage());
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar( title: 'Agenda'),
      body: _getCurrentPage(),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentPageIndex,
        onTap: (index){
          setState(() {
            _currentPageIndex = index;
          });
        },
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.content_paste),
            title: Text('Agenda'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.group),
            title: Text('Speakers'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.menu),
            title: Text('Menu'),
          ),
        ],
      ),
    );
  }
}

现在让我们说我希望我的AgendaPage小部件在视图顶部显示选项卡。有没有简单,非hacky方式来做到这一点?

期望的效果:Tabs page

No Tabs page

dart flutter cross-platform flutter-layout
2个回答
0
投票

您可以使用嵌套的Scaffold小部件。这适用于Flutter 1.1.8:

// This is the outer Scaffold. No AppBar here
Scaffold(
  // Workaround for https://github.com/flutter/flutter/issues/7036
  resizeToAvoidBottomPadding: false, 
  body: _getCurrentPage(),  // AppBar comes from the Scaffold of the current page 
  bottomNavigationBar: BottomNavigationBar(
    // ...
  )
)

0
投票

据我所知你不能,但我设法通过在AppBar导航的每个页面添加一个单独的bottomNavigationBar来解决这个问题:

为您的每个_pages提供一个单独的应用程序栏,并从您的build方法中删除主要的。

© www.soinside.com 2019 - 2024. All rights reserved.