Image 在颤振中添加到AppBar时,部分图像未显示
当我尝试在Flatter中将图像添加到Appbar时,如下所示:Image 在颤振中添加到AppBar时,部分图像未显示,image,flutter,flutter-appbar,Image,Flutter,Flutter Appbar,当我尝试在Flatter中将图像添加到Appbar时,如下所示: appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: AppBar( centerTitle: true, title: Image.asset('images/Ataxx.jpg'), ), ) 我得到以下输出: 正如您所看到的,顶部缺少部分图
appBar: PreferredSize(
preferredSize: Size.fromHeight(100.0),
child: AppBar(
centerTitle: true,
title: Image.asset('images/Ataxx.jpg'),
),
)
我得到以下输出:
正如您所看到的,顶部缺少部分图像!如何纠正这一点?谢谢。首先,我认为没有必要使用
PreferredSizeWidget
,因为AppBar
本身已经实现了PreferredSizeWidget
此外,我习惯于将图像放置在应用程序栏中-有关如何使用它,请参见示例代码。正如@rgisi建议的那样,您确实不需要使用
PreferredSize()
您只需要在标题中传递图像即可
appBar: AppBar(
titleSpacing: 0,
elevation: 0,
title: Image.network(
'https://images-eu.ssl-images-amazon.com/images/I/71ZFcWRAX7L.png',
fit: BoxFit.cover,
),
),
对于您的用例,如果您真的想使用PreferredSize()
,您可以这样使用它
appBar: PreferredSize(
preferredSize: Size.fromHeight(100),
child: Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.network(
'https://images-eu.ssl-images-amazon.com/images/I/71ZFcWRAX7L.png',
fit: BoxFit.cover,
),
),
),
),
你会得到这样的结果