【问题标题】:Set the container as the child of the bottom nav bar but there is a space between the bottom of the screen and the nav bar now将容器设置为底部导航栏的子级,但现在屏幕底部和导航栏之间有一个空间
【发布时间】:2021-11-15 20:53:35
【问题描述】:

所以我按照教程创建了自己的底部应用栏。但是,底部导航栏和屏幕底部之间有一个空白区域。我把这个空间涂成白色来展示它。如何使我的容器成为实际的导航栏并隐藏该空间?


import 'package:flutter/material.dart';

class bottomAppBar extends StatelessWidget {
  const bottomAppBar({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BottomAppBar(
      color: Colors.white,
      child: Container(
        color: Color(0xFF313131).withOpacity(0.7),
        height: 50,
        width: double.maxFinite,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            IconButton(
              onPressed: () {
                Navigator.pushNamed(context, '/');
              },
              icon: Icon(
                Icons.home,
                color: Colors.white,
              ),
            ),
            IconButton(
              onPressed: () {
                Navigator.pushNamed(context, '/discover');
              },
              icon: Icon(
                Icons.search,
                color: Colors.white,
              ),
            ),
            IconButton(
              onPressed: () {
                Navigator.pushNamed(context, '/mybookings');
              },
              icon: Icon(
                Icons.hello,
                color: Colors.white,
              ),
            ),
            IconButton(
              onPressed: () {
                Navigator.pushNamed(context, '/user');
              },
              icon: Icon(
                Icons.person,
                color: Colors.white,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

【问题讨论】:

  • 尝试将 Scaffold backgroundColor 设置为 Color(0xFF313131).withOpacity(0.7)

标签: flutter dart flutter-layout


【解决方案1】:

你把SafeArea 放在你的脚手架上了吗?当您使用 SafeArea 小部件并且您的屏幕不是矩形时,可能会发生这种情况,它会在屏幕的顶部和底部创建填充。

【讨论】:

  • 不,我没有使用安全区域小部件,它在其他屏幕上也像这样显示,我只有底部导航栏
猜你喜欢
  • 1970-01-01
  • 2020-03-06
  • 2022-11-23
  • 1970-01-01
  • 2022-10-22
  • 1970-01-01
  • 1970-01-01
  • 2022-11-29
  • 1970-01-01
相关资源
最近更新 更多