【问题标题】:Drawer Header Image Not filling the screen抽屉标题图像未填满屏幕
【发布时间】:2021-08-19 09:05:09
【问题描述】:

所以我在我的颤振应用程序中构建了一个抽屉(我第一次使用它),然后有些事情困扰着我。因此,当您将图像放入抽屉标题时,图像本身不会到达屏幕顶部。

图片:

这是我的抽屉代码:

drawer: Drawer(
        child: ListView(
          children: <Widget>[
            DrawerHeader(
              padding: EdgeInsets.zero,
              decoration: BoxDecoration(
                color: Colors.blue,
                image: DecorationImage(
                    fit: BoxFit.cover,
                    image: AssetImage("assets/images/fighters.jpg")),
              ),
              child: Center(
                child: Text(
                  "Menu",
                  style: TextStyle(
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                    fontSize: 30,
                  ),
                ),
              ),
            )
          ],
        ),
      ),

我没有为代码添加任何填充

请帮我解决这个问题,感谢任何帮助,谢谢!

【问题讨论】:

  • 尝试使用 BoxFit.fill 或 fitHeight。此外,将drawerheader 放在listview 中也是不明智的。而是使用 column 然后 listview。

标签: android ios flutter dart flutter-layout


【解决方案1】:

试试这个:

drawer: SafeArea(
    top: false,
    child: Drawer(..),
  ),

MediaQuery.removePadding(
          context: context,
          removeTop: true,
          child: ListView

【讨论】:

  • 感谢您的回复,但是当我把 top : false 放在抽屉里时,我的图像仍然保持不变。
  • 哇,谢谢!我添加了它,现在图像触及顶部。谢谢你的回答!
【解决方案2】:

使用 Column 而不是 Listview。

drawer: Drawer(
            child: Column(
              children: <Widget>[
                DrawerHeader(
                  padding: EdgeInsets.zero,
                  decoration: BoxDecoration(
                    color: Colors.blue,
                    image: DecorationImage(
                        fit: BoxFit.cover,
                        image: AssetImage("assets/images/main_top.png")),
                  ),
                  child: Center(
                    child: Text(
                      "Menu",
                      style: TextStyle(
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontSize: 30,
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 2019-09-07
    相关资源
    最近更新 更多