繁体   English   中英

如何在顶部和左侧边距领先图标 flutter

[英]How to margin top and left the leading Icon flutter

我在 Apppbar 上的左边距和顶部遇到问题,正在使用leading图标,但我未能重新定位它。

下面是我的代码:

child: Scaffold(
            appBar: PreferredSize(
              preferredSize: Size.fromHeight(150.0),
              child: AppBar(
                leading: SizedBox(
                  width: 200,
                height: 200,

                child: Transform.scale(scale: 2,
                    child: IconButton(
                      icon: Image.asset('assets/app_logo.png')
                  ,
                ),
                )
                ),
            centerTitle: true,
            actions: <Widget>[
              IconButton(
                  icon: Image.asset('assets/path.png'))
            ],
            bottom: TabBar(
                labelColor: Colors.white,
                indicatorColor: Colors.lime,

                tabs:[
                  Tab(icon: null,text: 'RECENT',),
                  Tab(icon: null, text: 'TOPICS',),
                  Tab(icon: null, text: 'AUTHORS',),
                ]
            ),
          )

这是我为leading图标设置样式的地方:

leading: SizedBox(
                      width: 200,
                    height: 200,

                    child: Transform.scale(scale: 2,
                        child: IconButton(
                          icon: Image.asset('assets/app_logo.png')
                      ,
                    )

这是屏幕截图:

在此处输入图像描述

我认为您无法轻松更改有关AppBar 布局的领先小部件的大小

但是您可以使用Stack小部件将您的徽标放在 AppBar 上,如下所示:

@override
Widget build(BuildContext context) {
  return MaterialApp(
    home: Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(150.0),
        child: Stack(
          children: <Widget>[
            AppBar(
              bottom: TabBar(
                controller: _tabController,
                labelColor: Colors.white,
                indicatorColor: Colors.lime,
                tabs: [
                  Tab(
                    icon: null,
                    text: 'RECENT',
                  ),
                  Tab(
                    icon: null,
                    text: 'TOPICS',
                  ),
                  Tab(
                    icon: null,
                    text: 'AUTHORS',
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.only(left: 20, top: 60),
              child: Container(
                width: 50,
                height: 50,
                color: Colors.yellow,
                child: Center(child: Text('Logo')),
              ),
            ),
          ],
        ),
      ),
    ),
  );
}

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM