首页 > 建站教程 > APP开发,混合APP >  Flutter报错:Cannot provide both a color and a decoration正文

Flutter报错:Cannot provide both a color and a decoration

我爱模板网使用Flutter没多久,经常会犯一些低级错误,比如,今天写了如下的代码:
Container(
  color: Colors.white,
  padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(27.0), ScreenUtil().setWidth(27.0), ScreenUtil().setWidth(27.0), ScreenUtil().setWidth(20)),
  height: ScreenUtil().setHeight(272.0),
  decoration: BoxDecoration(
    border: Border(bottom: BorderSide(width:.5, color: ConfigColor.INPUT_BORDER_COLOR)),
    borderRadius: BorderRadius.only(
      topLeft: Radius.circular(ScreenUtil().setWidth(11.0)),
      topRight: Radius.circular(ScreenUtil().setWidth(11.0)),
    )
  ),
  child: Column(
    children: [
      _title('欢迎新朋友加入', '2020/4/19  10:57', false),
      _description('欢迎您的到来,为了更好评估l健康和给予建议,请填写健康调查问卷(健康- -- ->问卷)'),
    ],
  ),
),
一运行出现了下面的提示:

Cannot provide both a color and a decoration
To provide both, use "decoration: BoxDecoration(color: color)".
'package:flutter/src/widgets/container.dart':
Failed assertion: line 285 pos 15: 'color == null || decoration == null'



原因很简单,Container的color属性和decoration属性不能同时出现,因为decoration里面也有color属性。将color放到decortaion里面即可:
Container(
  padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(27.0), ScreenUtil().setWidth(27.0), ScreenUtil().setWidth(27.0), ScreenUtil().setWidth(20)),
  height: ScreenUtil().setHeight(272.0),
  decoration: BoxDecoration(
    color: Colors.white,
    border: Border(bottom: BorderSide(width:.5, color: ConfigColor.INPUT_BORDER_COLOR)),
    borderRadius: BorderRadius.only(
      topLeft: Radius.circular(ScreenUtil().setWidth(11.0)),
      topRight: Radius.circular(ScreenUtil().setWidth(11.0)),
    )
  ),
  child: Column(
    children: [
      _title('欢迎新朋友加入', '2020/4/19  10:57', false),
      _description('欢迎您的到来,为了更好评估l健康和给予建议,请填写健康调查问卷(健康- -- ->问卷)'),
    ],
  ),
),