当前位置:网站首页>Shutter: add gradient stroke to font
Shutter: add gradient stroke to font
2022-07-03 12:06:00 【J_ D_ Chi】
List of articles
Write it at the front
Achieve the effect shown in the figure below , This number has gradients inside and outside .
Content
Realize stroke
Search the Internet for a round , You can see by using Stack, Let's make two Text superposition , And to the previous Text Set external stroke , You can get the following results .
Stack(
alignment: Alignment.center,
children: [
Text(
'100',
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 6
..color = Colors.black),
),
Text(
'100',
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold),
),
],
)
Achieve gradient
Color gradient use ShaderMask To process , It can help us calculate the rectangle of the text , Then we set it directly to LinearGradient that will do .
In the use of ShaderMask When , The color of the font needs to be white . Due to stroke Text We use foreground To add stroke , Therefore, the color setting should also be handled here , Not like another Text equally , stay TextStyle Inside color Property settings , Otherwise, an error will be reported .
Stack(
alignment: Alignment.center,
children: [
ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFF8F1FFF), Color(0xFFFF00FF)],
).createShader(Offset.zero & bounds.size);
},
child: Text(
'100',
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 6
..color = Colors.white),
),
),
ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.white, Color(0xFFFFBDE9)],
).createShader(Offset.zero & bounds.size);
},
child: Text(
'100',
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold),
),
)
],
)

Some adjustments
The above has basically achieved our initial effect , But there is still a problem , That is, there is some whiteness on the edge of the text , This is because of the tracing strokeWidth Some big , It exceeds the rectangular range of the text , Our gradient rendering range is only within the rectangle .
It can be seen here that some parts have crossed the left and right borders :
If you use English characters , It will be more obvious :
For these situations , I am currently dealing with two kinds :
- For the case of left and right boundaries , Add white space characters before and after the text :

- For the case of upper and lower boundaries , adjustment
TextStyleinheightattribute :
ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFF8F1FFF), Color(0xFFFF00FF)],
).createShader(Offset.zero & bounds.size);
},
child: Text(
'you',
style: TextStyle(
fontSize: 40,
height: 1.4,
fontWeight: FontWeight.bold,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 6
..color = Colors.white),
),
)
Reference resources
How to decorate text stroke in Flutter?
How to create gradient text in Flutter
边栏推荐
- Interview experience in summer camp of Central South University in 2022
- Solution à la défaillance de l'installation d'Electron
- Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
- SystemVerilog -- OOP -- copy of object
- 解决msvcp120d.dll和msvcr120d.dll缺失
- Optimize interface performance
- Dart: About zone
- OpenGL draws colored triangles
- (construction notes) grasp learning experience
- Raven2 of vulnhub
猜你喜欢

MCDF Experiment 1

Unicode encoding table download

Xiaopeng P7 hit the guardrail and the airbag did not pop up. The official responded that the impact strength did not meet the ejection requirements

vulnhub之presidential

Download address and installation tutorial of vs2015

Momentum of vulnhub

836. Merge sets (day 63) and search sets

Unity3d learning notes 5 - create sub mesh

错排问题 (抽奖,发邮件)

Solve msvcp120d DLL and msvcr120d DLL missing
随机推荐
Qt OpenGL 纹理贴图
vulnhub之cereal
OpenGL index cache object EBO and lineweight mode
libvirt 中体验容器
PHP导出word方法(一phpword)
为什么我的mysql容器启动不了呢
网络通讯之Socket-Tcp(一)
(construction notes) learning experience of MIT reading
Groovy测试类 和 Junit测试
Symlink(): solution to protocol error in PHP artisan storage:link on win10
Momentum of vulnhub
MySQL union和union all区别
laravel 时区问题timezone
023(【模板】最小生成树)(最小生成树)
在CoreOS下部署WordPress实例教程
Go language to realize static server
Vulnhub's presidential
SLF4J 日志门面
PHP導出word方法(一mht)
vulnhub之presidential