不能同时为容器提供颜色和装饰

Cannot provide both a color and a decoration to a Container

每次我重新启动代码以检查应用程序时,都会出现一个错误,提示 无法同时提供颜色和装饰,颜色参数只是“装饰:新 Boxdecoration”的缩写(颜色:颜色)“ 也许它是真的,我有一个错误,但它没有说明它在哪里? 当我删除诸如字体大小、小部件或与错误无关的内容并重新加载应用程序时,应用程序启动时没有任何问题或错误显示...


import './ui/TransAction.dart';
import './ui/SheetStack.dart';

void main() => runApp(MoneyMain());

class MoneyMain extends StatelessWidget {
  final String appName = 'Money Check';
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        floatingActionButtonTheme:
            FloatingActionButtonThemeData(backgroundColor: Colors.grey),
      ),
      debugShowCheckedModeBanner: false,
      title: appName,
      home: MoneyCheckHome(appName),
    );
  }
}

class MoneyCheckHome extends StatefulWidget {
  final String appName;
  MoneyCheckHome(this.appName);

  @override
  _MoneyCheckHomeState createState() => _MoneyCheckHomeState(appName);
}

class _MoneyCheckHomeState extends State<MoneyCheckHome> {
  final String appName;
  _MoneyCheckHomeState(this.appName);

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        appBar: AppBar(
          title: Text(appName),
        ),
        body: Container(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              SheetStack(),
              TransAction(),
            ],
          ),
        ),
      ),
    );
  }
}
import '../ux/TransActionUx.dart';

class TransAction extends StatefulWidget {
  @override
  _TransActionState createState() => _TransActionState();
}

class _TransActionState extends State<TransAction> {
  List<TransActionUx> tr = [];

  _TransActionState() {
    tr = [
      TransActionUx(
        title: 'New_shoes',
        date: DateTime.now(),
        price: 22.99,
        id: DateTime.now(),
      ),
      TransActionUx(
        title: 'new_shirt',
        date: DateTime.now(),
        price: 10.99,
        id: DateTime.now(),
      ),
      TransActionUx(
        title: 'new_shirt',
        date: DateTime.now(),
        price: 10.99,
        id: DateTime.now(),
      ),
    ];
  }

  Widget trMaker(List tr) {
    return Container(
      width: double.infinity,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10),
      ),
      child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: tr.map((trElemEnt) {
            return Container(
              child: Card(
                margin: EdgeInsets.all(10),
                elevation: 5,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    Container(
                      margin: EdgeInsets.all(5.0),
                      child: CircleAvatar(
                        radius: 25,
                        child: Text(
                          trElemEnt.price.toString(),
                        ),
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.only(left: 5.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text(
                            trElemEnt.title,
                            style: TextStyle(fontWeight: FontWeight.bold),
                          ),
                          SizedBox(
                            height: 3.0,
                          ),
                          Text(
                            trElemEnt.date.toString(),
                            style: TextStyle(
                                fontSize: 11,
                                color: Colors.grey,
                                fontWeight: FontWeight.bold),
                          )
                        ],
                      ),
                    )
                  ],
                ),
              ),
            );
          }).toList()),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        trMaker(tr),
      ],
    );
  }
} ```

您不能同时为 Container() 提供颜色和装饰。如果您希望为 Container 提供颜色和装饰,请在 Boxdecoration() 中提供颜色。下面的代码将起作用。

Container(
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(10),
)),

尝试在 decoration 中添加 color,如下所示:

Container(
  decoration: BoxDecoration(
    color: Colors.red
  ),
  child: //add you desired code here
),

这一定能帮到你