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
更多回答
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链接
我是一名优秀的程序员,十分优秀!