如何解决Flutter将IconButton内容与父边界对齐
是否可以使IconButton内容(图标)与父窗口小部件边界对齐?
这样的代码
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,children: <Widget>[
IconButton(
onpressed: () {
Navigator.of(context).pop();
},splashRadius: 20,constraints: BoxConstraints(),padding: EdgeInsets.zero,icon: SvgPicture.asset('assets/icons/arrow_left.svg',color: primaryColor)
)
],)
);
我想使“图标”与“行”小部件的左边界对齐,并在该位置周围保持单击时的启动动画。
使用此参数可以将Icon放置在我需要的位置,但是单击时的启动动画仍未对齐。
alignment: Alignment.centerLeft
因此它会执行以下操作(垂直标记线是父窗口小部件的边界)
但是我需要这个
解决方法
我相信这是资源,而不是代码。
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,children: <Widget>[
IconButton(
constraints: BoxConstraints(),padding: EdgeInsets.zero,icon: Icon(Icons.arrow_back,size: 20),splashRadius: 20,onPressed: () => {},),],)
)
我使用了您的代码,增加了代码的大小,并使用了内置资源。
icon: Icon(Icons.arrow_back,
输出为
,您可以通过以下简单方式使用它。
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.black12,borderRadius: BorderRadius.circular(50)),child: Padding(
padding: const EdgeInsets.all(16.0),child: IconButton(
onPressed: () {
Navigator.of(context).pop();
},constraints: BoxConstraints(),icon: SvgPicture.asset('assets/icons/arrow_left.svg',color: primaryColor)),)
],))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。