Flutter 使用线性渐变时,颤振堆栈的子对象是透明的
我使用的是一个堆栈,其中save60%折扣小部件位于具有白色背景的容器顶部。我在折扣容器上使用梯度。我希望渐变是实心的,但正如你在图像中看到的,它是半透明的,我们可以看到它下面的白色背景 我的堆栈代码是:Flutter 使用线性渐变时,颤振堆栈的子对象是透明的,flutter,flutter-layout,Flutter,Flutter Layout,我使用的是一个堆栈,其中save60%折扣小部件位于具有白色背景的容器顶部。我在折扣容器上使用梯度。我希望渐变是实心的,但正如你在图像中看到的,它是半透明的,我们可以看到它下面的白色背景 我的堆栈代码是: Container( width: width * 0.38, height: 250, child: Stack( children: [ Positioned( top: 20,
Container(
width: width * 0.38,
height: 250,
child: Stack(
children: [
Positioned(
top: 20,
child: InkWell(
onTap: () {},
child: Container(
width: width * 0.38,
height: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 35.h),
buildProductPrice(product, _intros),
buildCheckMark(product),
],
),
),
),
),
Align(
alignment: Alignment.topCenter,
child: buildDiscountText(product, _intros)),
],
),
);
为了获得坚实的背景,我可以用容器包装buildDiscountTextWidget并提供相同的渐变,然后做2,3次,但我认为这不是正确的方法
您只需要从Colors.lightBlue.withOpacity0.8的末尾删除.withOpacity0.8,您只需要从Colors.lightBlue.withOpacity0.8的末尾删除.withOpacity0.8,如下更改buildDiscountText小部件:
return Container(
height: 40,
width: 100,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.lightBlue, //remove opacity
Color(0xffCE41FD),
],
end: Alignment.centerRight,
begin: Alignment.centerLeft,
),
borderRadius: BorderRadius.circular(20)),
child: Text(
'SAVE $_rounded %',
style: _saveTextStyle,
),
);
将buildDiscountText小部件更改如下:
return Container(
height: 40,
width: 100,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.lightBlue, //remove opacity
Color(0xffCE41FD),
],
end: Alignment.centerRight,
begin: Alignment.centerLeft,
),
borderRadius: BorderRadius.circular(20)),
child: Text(
'SAVE $_rounded %',
style: _saveTextStyle,
),
);
我添加了不透明度以获得所需的渐变。我并没有意识到这是造成透明度的原因。那个么你们得到满意的结果了吗?我添加了不透明度来获得想要的梯度。我不知道这会导致透明度。所以你们得到满意的结果了吗?