dart - Flutter 底部导航,其中一页有选项卡

标签 dart flutter cross-platform flutter-layout

我想创建一个带有底部导航栏的脚手架,以及一个始终显示当前页面标题的应用栏。当我更改底部栏选项时,内容会发生明显变化。到目前为止,经典的 NavigationBar 结构一切正常。但是当内容页面上应该有标签时,问题就开始了。我在 parent 脚手架中创建了我的应用栏。无论如何要向父小部件 appBar 添加选项卡?

我的 AppBar + BottomNavBar 页面:

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 小部件在 View 顶部显示选项卡。有没有简单的,非hacky的方法来做到这一点?

想要的效果:
Tabs page

No Tabs page

最佳答案

您可以使用嵌套 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(
    // ...
  )
)

关于dart - Flutter 底部导航,其中一页有选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54659549/

相关文章:

firebase - Dart 错误 : Unhandled exception: E/flutter ( 5079): Invalid argument: Instance of 'Future<String>'

dart - ObjectStore放置语法

string - 在字符串列表上实现搜索

android - 在 Flutter 中获取 Android Activity 结果

android - 在 Android Listview 中显示内部用部分表示的设置

flutter - 如何在flutter_swiper中动态禁用滑动按钮?

android-studio - flutter开发时如何配置log cat

json - 类型错误问题将对象列表从 Json 转换为类结构

windows - 如何在 Windows 中为 Visual Studio 项目创建 Debian 安装包?

c++ - 除了 boost 之外,在 C++ 中获取目录中所有文件的跨平台方式