gpt4 book ai didi

flutter - 在 Flutter + Padding 中剪切文本效果

转载 作者:IT王子 更新时间:2023-10-29 06:44:48 25 4
gpt4 key购买 nike

我正在尝试实现 一些 Cut Out Text Effect,如 https://stackoverflow.com/a/55570169/8096916 中所示.

在我想向文本添加 Vertical padding 之前,它运行良好。

Imgur

正常:

ShaderMask(
blendMode: BlendMode.srcOut,
shaderCallback: (bounds) =>
LinearGradient(colors: [Colors.white], stops: [0.0]).createShader(bounds),
child: Text('Example'),
);

水平填充:

ShaderMask(
blendMode: BlendMode.srcOut,
shaderCallback: (bounds) =>
LinearGradient(colors: [Colors.white], stops: [0.0]).createShader(bounds),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child:
Text('Example'),
),);

有垂直填充

ShaderMask(
blendMode: BlendMode.srcOut,
shaderCallback: (bounds) =>
LinearGradient(colors: [Colors.white], stops: [0.0]).createShader(bounds),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child:
Text('Example'),
),);

我也尝试在 TextStyle 中给出高度,但效果与垂直填充相同。

最佳答案

您可以使用 Container 而不是 Padding 来修复它,尝试下一个:

ShaderMask(
blendMode: BlendMode.srcOut,
shaderCallback: (bounds) =>
LinearGradient(colors: [Colors.white], stops: [0.0]).createShader(bounds),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: Text('Example'),
),
),

关于flutter - 在 Flutter + Padding 中剪切文本效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56914823/

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