首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何删除我的自定义应用程序栏底部的水平白线?

如何删除我的自定义应用程序栏底部的水平白线?
EN

Stack Overflow用户
提问于 2022-04-02 02:11:01
回答 1查看 625关注 0票数 2

因此,我正在尝试制作一个自定义可重用的appbar小部件,如下所示

代码语言:javascript
运行
复制
class MyCustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  const MyCustomAppBar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final primaryColor = Theme.of(context).primaryColor;
    return AppBar(
      backgroundColor: primaryColor,
      elevation: 0, // to remove drop shadow
      titleSpacing: 0, // to remove extra padding on appbar left side
      title: Text("This Is appbar Title"),
    );
  }

  @override
  Size get preferredSize => const Size.fromHeight(50.0);
}

然后我用它在我的脚手架上像这样

代码语言:javascript
运行
复制
class NotificationListPage extends StatelessWidget {
  const NotificationListPage({Key? key}) : super(key: key);

  @override
  Widget build(context) {
    return Scaffold(
      appBar: MyCustomAppBar(),
      body: Column(
        children: [
          Container(
            width: double.infinity,
            height: 100,
            color: Theme.of(context).primaryColor,
            child: Center(
              child: Text(
                "this is container that has the same color with appbar",
                style: TextStyle(
                  fontSize: 10,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

其结果是:

如您所见,在列内的appbar和容器之间有一条白色的水平线。而且它只会在Android上追加。怎么移除这个?

如果我将Scaffold背景色改为红色,那么这条水平线也会变成红色。

我需要定制一个可重用的小部件。如果我像下面的代码那样直接实现(没有小部件分离),那条水平线就不会出现。

代码语言:javascript
运行
复制
class NotificationListPage extends StatelessWidget {
  const NotificationListPage({Key? key}) : super(key: key);

  @override
  Widget build(context) {
    final primaryColor = Theme.of(context).primaryColor;
    return Scaffold(
      appBar: AppBar( // I don't want to implement it directly like this. I want separate Appbar widget
        backgroundColor: primaryColor,
        elevation: 0, // to remove drop shadow
        titleSpacing: 0, // to remove extra padding on appbar left side
        title: Text("This Is appbar Title"),
      ),
      body: Column(
        children: [
          Container(
            width: double.infinity,
            height: 100,
            color: Theme.of(context).primaryColor,
            child: Center(
              child: Text(
                "this is container that has the same color with appbar",
                style: TextStyle(
                  fontSize: 10,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-04-02 04:37:23

因为你的Scaffold背景色是白色的。

代码语言:javascript
运行
复制
return Scaffold(
      backgroundColor: primaryColor,
      appBar: AppBar(...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71714352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档