Flutter关于盒子装饰中的颜色。

huangapple go评论59阅读模式
英文:

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),
  ),

huangapple
  • 本文由 发表于 2023年2月14日 20:55:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448150.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定