gpt4 book ai didi

flutter - 了解 Flutter 的 ShaderMask

转载 作者:IT王子 更新时间:2023-10-29 07:15:39 26 4
gpt4 key购买 nike

我正在尝试了解 ShaderMask 的工作原理。如果我遵循 ShaderMask 文档中的示例 here :

ShaderMask(
shaderCallback: (Rect bounds) {
return RadialGradient(
center: Alignment.topLeft,
radius: 1.0,
colors: <Color>[Colors.yellow, Colors.deepOrange.shade900],
tileMode: TileMode.mirror,
).createShader(bounds);
},
child: const Text('I’m burning the memories'),
)

我明白了:

ShaderMask example output

(Text 下方的双线显然表示缺少 Theme)

然后,如果我将相同的 ShaderMask 包围在 Scaffold 中,我会得到:

Scaffold(
body: Center(
child: ShaderMask(
shaderCallback: (Rect bounds) {
return RadialGradient(
center: Alignment.topLeft,
radius: 1.0,
colors: <Color>[Colors.yellow, Colors.deepOrange.shade900],
tileMode: TileMode.mirror,
).createShader(bounds);
},
child: const Text('I’m burning the memories'),
),
),
);

ShaderMask with Scaffold

一切都过去了! ShaderMask 似乎只是被忽略了,文档中也没有提及此行为,Scaffold 为什么“禁用” ShaderMask?

最佳答案

你缺少 - blendMode 属性

有关 - blendMode property 的更多信息

工作代码:

    Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ShaderMask(
blendMode: BlendMode.srcATop, // Add this
shaderCallback: (Rect bounds) {
return RadialGradient(
center: Alignment.topLeft,
radius: 1.0,
colors: <Color>[Colors.yellow, Colors.deepOrange.shade900],
tileMode: TileMode.mirror,
).createShader(bounds);
},
child: const Text('I’m burning the memories'),
),
),
);
}

关于flutter - 了解 Flutter 的 ShaderMask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57454851/

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