Flutter 如何在颤振中混合多个渐变?
设计师在他们创建的Figma设计中结合了两个或多个渐变。在一些设计中,他们将径向梯度与线性梯度相结合;在其他一些设计中,他们将线性渐变与另一个线性渐变相结合 这是使用CSS可以轻松完成的事情,但在Flutter中,我还无法实现它。我已经阅读了几乎所有关于颤振的文档,但似乎看不到任何解决方案。我是否可以在不让设计师改变设计的情况下组合两个渐变Flutter 如何在颤振中混合多个渐变?,flutter,dart,mobile,cross-platform,Flutter,Dart,Mobile,Cross Platform,设计师在他们创建的Figma设计中结合了两个或多个渐变。在一些设计中,他们将径向梯度与线性梯度相结合;在其他一些设计中,他们将线性渐变与另一个线性渐变相结合 这是使用CSS可以轻松完成的事情,但在Flutter中,我还无法实现它。我已经阅读了几乎所有关于颤振的文档,但似乎看不到任何解决方案。我是否可以在不让设计师改变设计的情况下组合两个渐变 gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [ Color.fromARGB(255, 255, 255, 255),
Color.fromARGB(255, 218, 217, 217)]
)
),
//这是我在容器里做的。我把我的整个披肩包在一个容器里,让背景变成白色到浅灰色。渐变:LinearGradient(
如果你像这样混合多重梯度 所以试着这样做 正文:专栏(
儿童:[
容器(
装饰:盒子装饰(
梯度:线性梯度(
开始:Alignment.topRight,
结束:对齐。左下角,
颜色:[颜色。蓝色,颜色。红色]),
儿童:中心(
子:文本(
'',
样式:TextStyle(
字体大小:48.0,
fontWeight:fontWeight.bold,
颜色:颜色。白色),
),
),
),
容器(
装饰:盒子装饰(
梯度:线性梯度(
开始:Alignment.topRight,
结束:对齐。左下角,
颜色:[颜色。白色,颜色。黑色]),
儿童:中心(
子:文本(
'',
样式:TextStyle(
字体大小:48.0,
fontWeight:fontWeight.bold,
颜色:颜色。白色),
),
),
)
],
));
必须将容器包装在容器中才能达到此效果:
容器(
装饰:盒子装饰(
梯度:梯度,
),
子:容器(
装饰:盒子装饰(
梯度:梯度二,
),
孩子:内容,
),
)
适用于半透明渐变。尝试使用
Gradient.lerp(你的第一个梯度,你的第二个梯度,0.5)
两者必须是相同的类型这仍然使用单个渐变。问题是如何组合多个渐变。这仍然使用单个渐变。问题是如何组合多个渐变。
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [Colors.blue, Colors.red])),
children:<Widget> [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [Colors.blue, Colors.red])),
child: Center(
child: Text(
'',
style: TextStyle(
fontSize: 48.0,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
),
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [Colors.white, Colors.black])),
child: Center(
child: Text(
'',
style: TextStyle(
fontSize: 48.0,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
)
],
));