Flutter -如何更改抽屉标头图像的大小和对齐方式?

a6b3iqyw  于 2023-03-17  发布在  Flutter
关注(0)|答案(4)|浏览(145)

我试图创建一个抽屉和标题是标志。
如何更改抽屉标头图像的大小和对齐方式?
我希望图像小一些,并且左对齐。
我试过了,但无法调整大小和对齐方式。

样本代码:

Scaffold(
        key: _key,
        drawer: Drawer(
          child: ListView(
              // Important: Remove any padding from the ListView.
              padding: EdgeInsets.zero,
              children: [
                DrawerHeader(
                  padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
                  child: Image.asset(
                    'images/logo.png',
                    width: 10,
                  ),
                ),
              ]),
        ),
        appBar: PreferredSize(
          preferredSize: const Size.fromHeight(80.0),
          child: AppBar(
            backgroundColor: Colors.transparent,
            elevation: 0,
            flexibleSpace:
                Row(mainAxisAlignment: MainAxisAlignment.center, children: [
              Padding(
                padding: const EdgeInsets.only(top: 0),
                child: Image.asset(
                  'images/logo.png',
                  fit: BoxFit.cover,
                  width: 80,
                ),
              ),
            ]),
            leading: Padding(
              padding: const EdgeInsets.only(top: 20),
              child: IconButton(
                onPressed: () => _key.currentState!.openDrawer(),
                icon: const Icon(
                  Icons.menu,
                  size: 27,
                  color: Color(0xff5f2dea),
                ),
              ),
            ),
wfypjpf4

wfypjpf41#

只需将您Image Package 为COntainer,并给予其大小和对齐方式:

DrawerHeader(
                    padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
                    child: Container(
                      width: 30,
                      alignment: Alignment.centerLeft,
                      child: Image.asset(
                        'images/logo.png',
                        width: 10,
                      ),
                    ))
omqzjyyz

omqzjyyz2#

这非常简单,只要用一个容器 Package 图片小部件,并给予高度和宽度。

ia2d9nvy

ia2d9nvy3#

drawer: Drawer(
      child: Column(
        children: [
          DrawerHeader(
              child: Align(
            alignment: Alignment.centerLeft,
            child: Image.asset(
              "assets/icons/icon.png",
              height: 100,
              width: 100,
            ),
          )),
          Expanded(
            child: ListView(
              children: const [Text("widget 1"), Text("widget 2")],
            ),
          )
        ],
      ),
    ),
4xrmg8kj

4xrmg8kj4#

尝试以下代码将您的图像包裹在ContainerAlign小工具内并设置alignment: Alignment.centerLeft,

DrawerHeader(
          child: Container(
            alignment: Alignment.centerLeft,
            child: Image.network(
              'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Mastercard-logo.svg/800px-Mastercard-logo.svg.png',
              width: 50,
              height: 50,
            ),
          ),
        ),

结果-〉x1c 0d1x

相关问题