我正在试着让这个底部的导航杆飘动,现在我有一个挑战.我已经创建了一个mainagee.dart,我在其中放置了appbar和底部的导航条形码.选项卡的屏幕放在Screens文件夹中.这是我在底部导航栏中的代码



Padding(

              padding: const EdgeInsets.only(top: 0.0, bottom: 30, left: 50, right:50), 

              child: ClipRRect(

                borderRadius: BorderRadius.circular(30.0), // Rounded corners for all sides

                child: BottomNavigationBar(

                  backgroundColor: Colors.white,

                  type: BottomNavigationBarType.fixed,

                  currentIndex: _currentIndex,

                  onTap: (index) {

                    setState(() {

                      _currentIndex = index;

                    });

                  },

                  elevation: 0.0,

                  showSelectedLabels: false, // Hide labels for selected tab

                  showUnselectedLabels: false, // Hide labels for unselected tabs

                  items: [

                    BottomNavigationBarItem(

                      icon: Icon(Icons.home),

                      label: '', // Empty label

                    ),

                    BottomNavigationBarItem(

                      icon: Icon(Icons.search),

                      label: '', // Empty label

                    ),

                    BottomNavigationBarItem(

                      icon: Icon(Icons.favorite, ),

                      label: '', // Empty label

                    ),

                    BottomNavigationBarItem(

                      icon: Icon(Icons.person),

                      label: '', // Empty label

                    ),

                  ],

                ),

              ),

            ),

所以这里的 idea 是让底部导航栏浮动在标签屏幕的顶部,这样如果你在主页标签上,内容可以滚动到底部导航栏后面,就像下面这张照片中的琥珀色代表的内容.

this is the snippet of how I want the bottom  nav bar to be

But every time I call the body:pages[_currentIndex] the bottom navigation bar seems to be having a white background, or the color matching with the scaffold of the MainPage(). It's creating like it's on container

class MainMenu extends StatefulWidget {
  const MainMenu({super.key});
  static const String id = "landingpage";

  @override
  State<MainMenu> createState() => _MainMenuState();
}

class _MainMenuState extends State<MainMenu> {
  GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();



  int _currentIndex = 0;

  // Define your pages/screens
  final List<Widget> screens = [
    FavoritePage(),
    HomePage(),

    ListingsPage(),
    ProfilePage(),
  ];
  bool drawerCanOpen = true;
  final kDrawerItemStyle = TextStyle(
    fontSize: 16,
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.amber,
      bottomNavigationBar: Padding(
        padding: const EdgeInsets.only(top: 0.0, bottom: 30, left: 50, right:50), // Add padding to the entire bottom navigation bar
        child: ClipRRect(

          borderRadius: BorderRadius.circular(30.0), // Rounded corners for all sides
          child: BottomNavigationBar(
            backgroundColor: Colors.white,
            type: BottomNavigationBarType.fixed,

            currentIndex: _currentIndex,
            onTap: (index) {
              setState(() {
                _currentIndex = index;
              });
            },
            elevation: 0.0,

            showSelectedLabels: false, // Hide labels for selected tab
            showUnselectedLabels: false, // Hide labels for unselected tabs
            items: [
              BottomNavigationBarItem(
                icon: Icon(Icons.home),
                label: '', // Empty label


              ),
              BottomNavigationBarItem(

                icon: Icon(Icons.search),
                label: '', // Empty label
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.favorite, ),
                label: '', // Empty label

              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.person),
                label: '', // Empty label
              ),
            ],
          ),
        ),
      ),



      

      key: scaffoldKey,
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            _currentIndex <= 0
                ? SliverAppBar(

              foregroundColor: Color.fromARGB(255, 12, 3, 3),
              title: Row(children: [
                // Image.asset(
                //   'assets/logo1.png',
                //   height: 40,
                //   width: 40,
                // ),
                // Text('glacier'),
              ]
              ),
              leading: Padding(
                padding: const EdgeInsets.all(8.0),
                child: CircleAvatar(
                  backgroundColor: Color.fromARGB(255, 255, 255, 255),
                  radius: 20,
                  child: IconButton(
                    icon: FaIcon(FontAwesomeIcons.bars),
                    onPressed: () {
                      if (drawerCanOpen) {
                        scaffoldKey.currentState?.openDrawer();
                      } else {
                        setState(() {
                          drawerCanOpen = true;
                        });
                      }
                    },
                    color: Colors.black87,
                  ),
                ),
              ),
              actions: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Container(
                    decoration: BoxDecoration(
                      color: Color.fromARGB(255, 18, 255, 0),
                      borderRadius: BorderRadius.circular(20),
                      boxShadow: [
                        BoxShadow(
                          color: Colors.black26,
                          blurRadius: 5.0,
                          spreadRadius: 0.5,
                          offset: Offset(
                            0.7,
                            0.7,
                          ),
                        ),
                      ],
                    ),
                    child: Badge(
                      backgroundColor: Colors.red,
                      padding: const EdgeInsets.all(7),
                      textStyle: const TextStyle(fontSize: 10.0),
                      largeSize: 20.0,
                      label: const Text('1'),
                      child: CircleAvatar(
                        backgroundColor: Colors.white,
                        radius: 20,
                        child: IconButton(
                          icon: FaIcon(FontAwesomeIcons.bagShopping),
                          onPressed: () {
                            Get.to(() => const CartPage(),
                                duration:
                                const Duration(milliseconds: 200),
                                transition: Transition.rightToLeft);
                          },
                          color: Colors.black87,
                        ),
                      ),
                    ),
                  ),
                ),
              ],
              expandedHeight: 50,
              scrolledUnderElevation: 2,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(5.0)),
              floating: false,
              pinned: true,
              elevation: innerBoxIsScrolled ? 4 : 0,
              flexibleSpace: FlexibleSpaceBar(
                centerTitle: true,
                background: Container(
                  color: Colors.amber, // Set your desired background color here
                ),
              ),
            )
                : SliverToBoxAdapter(
              child: SizedBox.shrink(),
            ),
          ];
        },
        body: screens[_currentIndex],

        ),


    );
  }
}

推荐答案

ScaffoldextendBody属性设置为true.

Scaffold(
  extendBody: true,
  // ...
)

documentation人开始:

当BottomNavigationBar具有非矩形形状(如CircularNotchedRectangle)时,此属性通常很有用,后者将FloatingActionButton大小的凹槽添加到栏的上边缘.在这种情况下是specifying 100 ensures that scaffold's body will be visible through the bottom navigation bar's notch.

Flutter相关问答推荐

如何刷新future 的构建器时,没有OBS变量的内部在Ffltter?

如何在Firebase项目中更改包名称和包ID

Flutter 应用程序中的Firebase实时数据库中的orderByChild()不适用于我

如何从DART中的事件列表中获取即将到来的日期

如何在抖动中将PNG图像转换为WebP

围绕父组件旋转位置组件

我可以在列表图块下方添加其他小部件吗

更改底部导航栏下方 Flutter Snackbar 的位置

Flutter - 我需要显示文本,但应用程序不需要

通过一个具体的例子理解Flutter约束的本质

如何在 Flutter 中测试动画图标

Flutter - 根据从第一个 DropdownButtonForm 中 Select 的内容在第二个 DropdownButton 上显示选项

你如何在 Flutter 中组合两个数组?

flutter 创建一个带有 2 个图标的按钮

Android: 从 URI 获取音频元数据

Firebase 中的查询限制 - .orderBy() 错误

如何在 flutter 中过滤 DateTime(intl)?

运行Flutter 测试时出现 FirebaseAppPlatform.verifyExtends 错误

try 为两个下拉值添加共享首选项,但在 Flutter 上显示错误断言失败:?

小部件库捕获的 Flutter 异常