我在应用页面上的脚手架上添加了应用栏。一切正常,期望标题使用的资产SVG图像不总是居中。当我从另一个推送到应用程序栏的页面时,带有SVG图像的标题将移至右侧,如果直接访问该页面,则其将移至左侧。我尝试为此使用填充,但仍然相同。问题是如何使标题固定在中间,而不受左右操作按钮图像的影响。下面是我的代码:
return Scaffold(
backgroundColor: Colors.white,
appBar: PreferredSize(
preferredSize: Size.fromHeight(40.0), // here the desired height
child: AppBar(
backgroundColor: colorGreen,
title:Center(child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
//padding: const EdgeInsets.only(left: 36.0),
child: Center(
child: SvgPicture.asset(assetName,
color: Colors.white,
width: 20,
height: 20,
fit: BoxFit.cover,
semanticsLabel: 'Hobber'),
),
),
],
)),
actions: <Widget>[
GestureDetector(
child: Padding(
padding: const EdgeInsets.only(right: 12.0),
child: Icon(
Icons.notifications,
color: Colors.white,
),
),
onTap: () {},
),
],
),
),
body:Container(child:Text("My body message"),)
);
尝试以下操作:
appBar: AppBar(
centerTitle: true,
......
如果可行,我建议您尝试删除不必要的小部件