颜色不在自定义类中显示

问题描述 投票:0回答:1
 Expanded(
               //flex: 2,
               child: Row(
             children: <Widget>[
               Expanded(child: Reuseable(colour: Color(0xBAD681))),
               Expanded(
                   child: Reuseable(colour: Color(0xBAD681)),
                   )
             ],
           )),

   class Reuseable extends StatelessWidget {
   Reuseable({@required this.colour, this.cardChild});

   final Color colour;
   final Widget cardChild;

   @override
   Widget build(BuildContext context) {
     return Container(
       child: cardChild,
       margin: EdgeInsets.all(15.0),
       decoration: BoxDecoration(
         border: Border.all(
           color: Colors.grey,
         ),
           color: colour,
           borderRadius: BorderRadius.circular(10.0)),.
     );
  }
 }

这是我用来创建自定义类的代码的一部分,由于某种原因我无法对其进行着色!如果没有边界,那么可重用类将是不可见的,为什么以及如何解决它的任何想法?

截屏:

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS92NkczcC5wbmcifQ==” alt =“ https://i.ibb.co/pyMnVgJ/Screenshot>1592356692.png

Expanded(// flex:2,child:Row(children:[Expanded(child:Reuseable(color:Color(0xBAD681))),Expanded(...

flutter dart flutter-layout
1个回答
0
投票
您不能同时提供颜色和装饰color参数只是"decoration: new BoxDecoration(color: color)"的简写。

color中删除Container参数,并将其留在BoxDecoration:

© www.soinside.com 2019 - 2024. All rights reserved.