推送到页面和操作按钮可用时,Flutter Appbar 标题不居中
Flutter Appbar title not center when push to the page and when action button is available
我在 flutter 页面的脚手架上添加了 appbar。一切都完美无缺,但用于标题的资产 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,
......
删除不必要的小部件会使您的 appBar 得到以下结果:
appBar: PreferredSize(
preferredSize: Size.fromHeight(40.0), // here the desired height
child: AppBar(
centerTitle: true,
backgroundColor: colorGreen,
title: 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: () {},
),
],
),
),
我在 flutter 页面的脚手架上添加了 appbar。一切都完美无缺,但用于标题的资产 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,
......
删除不必要的小部件会使您的 appBar 得到以下结果:
appBar: PreferredSize(
preferredSize: Size.fromHeight(40.0), // here the desired height
child: AppBar(
centerTitle: true,
backgroundColor: colorGreen,
title: 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: () {},
),
],
),
),