当前位置:网站首页>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
TextStyle
inheight
attribute :
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
边栏推荐
- Unity3D学习笔记5——创建子Mesh
- Colleagues wrote a responsibility chain model, with countless bugs
- 解决msvcp120d.dll和msvcr120d.dll缺失
- Download address and installation tutorial of vs2015
- (数据库提权——Redis)Redis未授权访问漏洞总结
- Dart: About zone
- Deploying WordPress instance tutorial under coreos
- Optimize interface performance
- DNS multi-point deployment IP anycast+bgp actual combat analysis
- vulnhub之momentum
猜你喜欢
随机推荐
DEJA_VU3D - Cesium功能集 之 053-地下模式效果
(构造笔记)从类、API、框架三个层面学习如何设计可复用软件实体的具体技术
C language improvement article (wchar_t) character type
Solution à la défaillance de l'installation d'Electron
Dart: About zone
Socket TCP for network communication (I)
Sheet1$.输出[Excel 源输出].列[XXX] 出错。返回的列状态是:“文本被截断,或者一个或多个字符在目标代码页中没有匹配项。”。
Is BigDecimal safe to calculate the amount? Look at these five pits~~
Introduction to the implementation principle of rxjs observable filter operator
Dart: about grpc (I)
Shardingsphere sub database and sub table < 3 >
[MySQL special] read lock and write lock
Go language to realize static server
Groovy测试类 和 Junit测试
Redis notes 01: Introduction
Why can't my MySQL container start
OpenGL 索引缓存对象EBO和线宽模式
(构造笔记)GRASP学习心得
vulnhub之cereal
win10 上PHP artisan storage:link 出现 symlink (): Protocol error的解决办法