如何在 Flutter Shader 中实现从左上角到右下角的渐变效果?
How to do a Gradient effect from topLeft to botttomRgiht in Flutter Shader?
大家好,
我需要知道如何创建渐变色
从 topLeft 到 bottomRight 在 flutter 中的着色器中,就像这个图像中的示例 2
?
我尝试使用这个迷你着色器代码来执行此操作,但它仍然对我不起作用。
final Shader linearGradient = LinearGradient(
colors: <Color>[
Color(0xff002fff),
Color(0xff00f4ff),
],
).createShader(Rect.fromCircle(center: Offset(200, 0), radius: 150));
任何人都可以有一个想法,如何创建它?或者现在在 Flutter 中也不是不可能的 ♂️。
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
children: <Widget>[
Container(
width: 200,
height: 200,
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [Color(0xFF11F4B5), Color(0xFFCA436B)],
begin: FractionalOffset.centerLeft,
end: FractionalOffset.centerRight,
stops: [0.0, 1.0],
tileMode: TileMode.clamp)),
),
SizedBox(
height: 20,
),
Container(
width: 200,
height: 200,
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [Color(0xFF1cb5e1), Color(0xFF000046),Color(0xFF000000)],
begin: FractionalOffset.topLeft,
end: FractionalOffset.bottomRight,
stops: [0.0, 1.0],
tileMode: TileMode.mirror)),
),
],
)),
);
}
只需检查这是否有效,更改颜色即可获得所需的输出
您可以使用 LinearGradient 的 begin 和 end 属性。
例如:
LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Color(0xff002fff),
Color(0xff00f4ff),
],
),
大家好,
我需要知道如何创建渐变色
从 topLeft 到 bottomRight 在 flutter 中的着色器中,就像这个图像中的示例 2
?
我尝试使用这个迷你着色器代码来执行此操作,但它仍然对我不起作用。
final Shader linearGradient = LinearGradient(
colors: <Color>[
Color(0xff002fff),
Color(0xff00f4ff),
],
).createShader(Rect.fromCircle(center: Offset(200, 0), radius: 150));
任何人都可以有一个想法,如何创建它?或者现在在 Flutter 中也不是不可能的 ♂️。
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(
children: <Widget>[
Container(
width: 200,
height: 200,
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [Color(0xFF11F4B5), Color(0xFFCA436B)],
begin: FractionalOffset.centerLeft,
end: FractionalOffset.centerRight,
stops: [0.0, 1.0],
tileMode: TileMode.clamp)),
),
SizedBox(
height: 20,
),
Container(
width: 200,
height: 200,
decoration: new BoxDecoration(
gradient: new LinearGradient(
colors: [Color(0xFF1cb5e1), Color(0xFF000046),Color(0xFF000000)],
begin: FractionalOffset.topLeft,
end: FractionalOffset.bottomRight,
stops: [0.0, 1.0],
tileMode: TileMode.mirror)),
),
],
)),
);
}
只需检查这是否有效,更改颜色即可获得所需的输出
您可以使用 LinearGradient 的 begin 和 end 属性。
例如:
LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Color(0xff002fff),
Color(0xff00f4ff),
],
),