gpt4 book ai didi

flutter's text with gradient color appears differently in ios and android(在iOS和Android中,带有渐变颜色的Ffltter文本显示方式不同)

转载 作者:bug小助手 更新时间:2023-10-26 20:18:07 25 4
gpt4 key购买 nike



my flutter app is showing text with gradient color. this is my code

我的Ffltter应用程序正在显示渐变颜色的文本。这是我的代码


final Shader linearGradientShader = ui.Gradient.linear(
Offset(0, 20),
Offset(150, 20),
[Colors.red, Colors.yellow],
);
return Center(
child: FittedBox(
child: Text(
'#stackoverflow',
style: TextStyle(
foreground: Paint()..shader = linearGradientShader,
fontSize: 60,
fontWeight: FontWeight.bold,
),
),
),
);

However in ios device, the text is not as smooth as android. how can i fix this? image below is ios

然而,在iOS设备上,文本没有Android那么流畅。我怎么才能解决这个问题呢?下图为iOS


android
ios


更多回答

Are these "on device". The resolution of the simulators and emulators can be deceiving.

这些都是“在设备上”吗?模拟器和模拟器的分辨率可能具有欺骗性。

yes, both images are on device images

是的,这两个图像都在设备图像上

优秀答案推荐

Text rendering vary between Android and IOS, to improve this you can try setting the font size and antialiasing settings :

Android和iOS之间的文本呈现有所不同,要改善这一点,你可以尝试设置字体大小和抗锯齿设置:


final dpr = MediaQuery.of(context).devicePixelRatio;


MediaQuery.devicePixelRatio is a property that tells you the ratio of
physical pixels to logical pixels on a device’s screen.



Text('#stackoverflow'),
style:TextStyle(
foreground:Paint()..shader=linearGradientShader,
fontSize:60*dpr,
fontWeighty:FontWeight.bold,
textAntialias:true,),),

Try this hope this helped!

试一试,希望这能帮上忙!


You can read about MediaQuery.devicePixelRatio from here to have a clear idea about it :
https://flutterassets.com/most-popular-flutter-mediaquery-properties/#:~:text=devicePixelRatio%20in%20Flutter%3F-,MediaQuery.,of%20the%20device's%20pixel%20density.

你可以从这里阅读关于MediaQuery.devicePixelRatio的文章,以对其有一个清晰的了解:https://flutterassets.com/most-popular-flutter-mediaquery-properties/#:~:text=devicePixelRatio%20in%20Flutter%3F-,MediaQuery.,%20%20Device的%20Pixel%20密度。


更多回答

this helped, but still is not as clear as android's. Plus, I can't find textAntialias field in TextStyle. Any other recommendations?

这很有帮助,但仍然不像Android的那样清晰。另外,我在TextStyle中找不到文本反别名字段。还有其他建议吗?

Try using custom fonts , also try the package : super_text_layout 0.1.7 link

尝试使用自定义字体,也尝试软件包:Super_Text_Layout 0.1.7链接

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com