[英]Flutter: how do I give to colored container opacity?
why can't I assign opacity to the color in this container? 为什么不能为该容器中的颜色分配不透明度?
this works: 这有效:
class ColouredContainer extends StatelessWidget {
@override
Widget build(BuildContext context)=>
Container( decoration: BoxDecoration(color: greens[1]),);
}
this return the error below: 这将返回以下错误:
class ColouredContainer extends StatelessWidget {
@override
Widget build(BuildContext context)=>
Container( decoration: BoxDecoration(color: greens[1]
.withOpacity(50) /// <= THIS!
),
);
}
I/flutter (18323): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (18323): The following assertion was thrown building BackGround(dirty): I/flutter (18323): 'dart:ui/painting.dart': Failed assertion: line 188: '': is not true. I / flutter(18323):W小工具库引起的异常CA ═════════════════════════I / flutter(18323):构建BackGround(dirty)时引发了以下断言:I / flutter(18323): 'dart:ui / painting.dart':断言失败:188行:'':不正确。 I/flutter (18323): I/flutter (18323): Either the assertion indicates an error in the framework itself, or we should provide substantially I/flutter (18323): more information in this error message to help you determine and fix the underlying cause. I / flutter(18323):I / flutter(18323):要么断言表明框架本身有错误,要么我们应该提供I / flutter(18323):此错误消息中的更多信息,以帮助您确定和修复根本原因。 I/flutter (18323): In either case, please report this assertion by filing a bug on GitHub: I/flutter (18323): https://github.com/flutter/flutter/issues/new?template=BUG.md I / flutter(18323):无论哪种情况,请通过在GitHub上提交错误来报告此断言:I / flutter(18323): https : //github.com/flutter/flutter/flutter/issues/new? template = BUG.md
ultimately: how do I give to colored container opacity? 最终:如何使有色容器不透明?
thanks for the help 谢谢您的帮助
If you check the source code, the line 188 from painting.dart
: 如果您检查源代码,那么line 188 from painting.dart
的line 188 from painting.dart
:
Color withOpacity(double opacity) {
assert(opacity >= 0.0 && opacity <= 1.0);
return withAlpha((255.0 * opacity).round());
}
According to assert
function, you must enter some value between 0.0 & 1.0 inclusive. 根据assert
函数,您必须输入介于0.0和1.0之间的一个值。 That's the error. 那是错误。 So the answer: 所以答案是:
class ColouredContainer extends StatelessWidget {
@override
Widget build(BuildContext context)=>
Container( decoration: BoxDecoration(color: greens[1]
.withOpacity(0.5)
),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.