首页 > 解决方案 > 颤振:库比蒂诺标签栏

问题描述

如何使 Cupertino TabBar 以与 BottomNavigationBar 相同的方式工作?

底部导航栏

    return Scaffold(
      bottomNavigationBar: _bottomNavigationBar(_selectedIndex),
      body: PageStorage(
        child: pages[_selectedIndex],
        bucket: bucket,

库比蒂诺标签栏

final PageStorageBucket bucket = PageStorageBucket();
  int _selectedIndex = 1;

  Widget _tabBar(int selectedIndex) => CupertinoTabBar(
    onTap: (int index) => setState(() => _selectedIndex = index),
    currentIndex: selectedIndex,
    backgroundColor: Color(0xffffffff),
    iconSize: 20,
    items: ...

  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBuilder: _tabBar(_selectedIndex),
      child: PageStorage(
        child: pages[_selectedIndex],
        bucket: bucket,

标签: flutter

解决方案


推荐阅读