英文:
Flutter about color ib boxdecoration
问题
无法同时提供颜色和装饰。要同时提供它们,请使用"decoration: BoxDecoration(color: color)"。
'package:flutter/src/widgets/container.dart': container.dart:1 失败的断言: 第273行第15位: 'color == null || decoration == null'。
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(15),
child: Text(title),
color: color,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
color.withOpacity(0.7),
color,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(15),
),
);
}
英文:
> Cannot provide both a color and a decoration To provide both, use
> "decoration: BoxDecoration(color: color)".
> 'package:flutter/src/widgets/container.dart': container.dart:1 Failed
> assertion: line 273 pos 15: 'color == null || decoration == null'
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(15),
child: Text(title),
color: color,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
color.withOpacity(0.7),
color,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(15),
),
);
}
答案1
得分: 1
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(15),
child: Text(title),
color: color, ***--> 删除这一行!***
decoration: BoxDecoration(
color: color, ***--> 把这行放在这里!***
gradient: LinearGradient(
colors: [
color.withOpacity(0.7),
color,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(15),
),
);
}
英文:
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(15),
child: Text(title),
color: color, ***--> Delete this line!***
decoration: BoxDecoration(
color: color, ***--> Put that line here!***
gradient: LinearGradient(
colors: [
color.withOpacity(0.7),
color,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(15),
),
);
}
答案2
得分: 0
你似乎已经设置了一个decoration
,所以去掉color: color,
,因为不支持同时执行两者。
英文:
You seem to have set a decoration
already, so drop the color: color,
, because it's not suported to do both.
答案3
得分: 0
错误是不言自明的,它表示当你在容器中使用装饰时,你必须像这样在装饰中传递颜色:
decoration: BoxDecoration(
color: //颜色
gradient: LinearGradient(
colors: [
color.withOpacity(0.7),
color,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(15),
),
英文:
the error is self explanatory it says that when you are using decoration n the container you have to pass the color inside the decoration like this
decoration: BoxDecoration(
color: //color
gradient: LinearGradient(
colors: [
color.withOpacity(0.7),
color,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(15),
),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论