Flutter AppBar行对齐问题:缩小抽屉图标与其他元素间距
解决AppBar抽屉图标与其他图标间距过大的问题
问题出在你AppBar的title布局里,那个内容不完整的空Row占据了大量中间空间,把右侧图标组推到了最右边,导致和左侧抽屉图标间距过大。以下是两种修复方案:
方案一:移除空Row,调整title布局
直接删掉title里那个空Row,把图标组放在title的Row中,图标会自动靠近左侧的抽屉图标:
appBar: AppBar( iconTheme: IconThemeData(color: Colors.black), toolbarHeight: 70, elevation: 0.0, backgroundColor: Color(0xFFE5E5E5), title: Row( children: [ Icon( Icons.inbox_outlined, color: Colors.grey[600], ), SizedBox( width: 20, ), Icon(Icons.notifications_active_outlined, color: Colors.grey[600]), SizedBox( width: 20, ), CircleAvatar( child: Container( child: Icon( Icons.person, color: Colors.grey, ), ), backgroundColor: Colors.grey[300], ), ], ), ),
如果原来的空Row是用来放Logo的,补全Logo内容后,调整它和图标组的间距即可:
appBar: AppBar( iconTheme: IconThemeData(color: Colors.black), toolbarHeight: 70, elevation: 0.0, backgroundColor: Color(0xFFE5E5E5), title: Row( children: [ // 补全你的Logo容器 Container( padding: EdgeInsets.zero, height: 50, width: 80, child: Image.asset("你的Logo路径"), // 替换为实际Logo路径 ), SizedBox(width: 10), // 调整Logo与图标之间的间距 Icon( Icons.inbox_outlined, color: Colors.grey[600], ), SizedBox( width: 20, ), Icon(Icons.notifications_active_outlined, color: Colors.grey[600]), SizedBox( width: 20, ), CircleAvatar( child: Container( child: Icon( Icons.person, color: Colors.grey, ), ), backgroundColor: Colors.grey[300], ), ], ), ),
方案二:自定义leading,让图标与抽屉图标紧密排列
如果希望图标和抽屉图标完全挨在一起,可以自定义leading属性,手动添加抽屉图标和其他操作图标,把头像放在actions中:
appBar: AppBar( iconTheme: IconThemeData(color: Colors.black), toolbarHeight: 70, elevation: 0.0, backgroundColor: Color(0xFFE5E5E5), leading: Row( children: [ // 手动添加抽屉图标及点击事件 IconButton( icon: Icon(Icons.menu), onPressed: () => Scaffold.of(context).openDrawer(), ), SizedBox(width: 10), // 调整抽屉图标与下一个图标间距 Icon( Icons.inbox_outlined, color: Colors.grey[600], ), SizedBox(width: 20), Icon(Icons.notifications_active_outlined, color: Colors.grey[600]), ], ), actions: [ // 把头像放在右侧 Padding( padding: EdgeInsets.only(right: 16), child: CircleAvatar( child: Container( child: Icon( Icons.person, color: Colors.grey, ), ), backgroundColor: Colors.grey[300], ), ), ], ),
内容的提问来源于stack exchange,提问作者Iniisking
相关产品推荐
相关产品推荐

