Flutter 是否改变了它处理 Image 作为 AppBar 标题的方式?
Has Flutter changed how it handles an Image as AppBar title?
在我的 Flutter 应用程序中,我使用 png 图像作为 AppBar
中的标题。似乎在过去 24 小时内更改了它处理图像大小调整的方式。
在过去的一两个月里,这一直运行良好:在我的 MaterialApp
我的 StatefulWidget
returns 一个 AppBar
一个 Scaffold
里面其 title
设置为 Image.asset(assetName)
。 Image
会自动适当缩小以整齐地适合 AppBar
on-screen,一旦我添加了一点 padding
.
昨天,这个坏了。我已经检查了差异并且没有任何改变会明显影响代码的这一部分,因为它正在工作。我现在以全尺寸显示图像,这对于可用的 space 来说太大了大约 3 倍,因此它被裁剪了。
我已经尝试添加 fit: BoxFit.contain
,实际上所有其他可能的 BoxFit
选项 - 绝对没有区别。
我最终在 Image
上使用 height: AppBar().preferredSize.height * 0.6
作为解决方法。
return Scaffold(
appBar: AppBar(
title: Padding(
padding: EdgeInsets.symmetric(
vertical: 10,
),
child: Image.asset(kLogoImage, height:
AppBar().preferredSize.height * 0.6),
),
...
但我不明白为什么这突然改变了,而我似乎没有做任何影响它的事情。 Flutter 本身是否发生了某种转变以某种方式打破了这一点?
根据上面 Pablo 的评论,这确实是 Flutter 的一个变化。
要恢复原始的 AppBar 布局行为,请将 AppBar 的标题包装在高度为 kToolbarHeight 的 SizedBox 中。
appBar: AppBar(
title: SizedBox(
height: kToolbarHeight,
child: Image.asset(kLogoImage),
),
),
前面的例子引入了10个像素的垂直填充,所以:
appBar: AppBar(
title: SizedBox(
height: kToolbarHeight,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 10),
child: Image.asset(kLogoImage),
),
),
),
也在这里讨论:https://github.com/flutter/flutter/issues/44550#issuecomment-552586000。
在我的 Flutter 应用程序中,我使用 png 图像作为 AppBar
中的标题。似乎在过去 24 小时内更改了它处理图像大小调整的方式。
在过去的一两个月里,这一直运行良好:在我的 MaterialApp
我的 StatefulWidget
returns 一个 AppBar
一个 Scaffold
里面其 title
设置为 Image.asset(assetName)
。 Image
会自动适当缩小以整齐地适合 AppBar
on-screen,一旦我添加了一点 padding
.
昨天,这个坏了。我已经检查了差异并且没有任何改变会明显影响代码的这一部分,因为它正在工作。我现在以全尺寸显示图像,这对于可用的 space 来说太大了大约 3 倍,因此它被裁剪了。
我已经尝试添加 fit: BoxFit.contain
,实际上所有其他可能的 BoxFit
选项 - 绝对没有区别。
我最终在 Image
上使用 height: AppBar().preferredSize.height * 0.6
作为解决方法。
return Scaffold(
appBar: AppBar(
title: Padding(
padding: EdgeInsets.symmetric(
vertical: 10,
),
child: Image.asset(kLogoImage, height:
AppBar().preferredSize.height * 0.6),
),
...
但我不明白为什么这突然改变了,而我似乎没有做任何影响它的事情。 Flutter 本身是否发生了某种转变以某种方式打破了这一点?
根据上面 Pablo 的评论,这确实是 Flutter 的一个变化。
要恢复原始的 AppBar 布局行为,请将 AppBar 的标题包装在高度为 kToolbarHeight 的 SizedBox 中。
appBar: AppBar(
title: SizedBox(
height: kToolbarHeight,
child: Image.asset(kLogoImage),
),
),
前面的例子引入了10个像素的垂直填充,所以:
appBar: AppBar(
title: SizedBox(
height: kToolbarHeight,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 10),
child: Image.asset(kLogoImage),
),
),
),
也在这里讨论:https://github.com/flutter/flutter/issues/44550#issuecomment-552586000。