Cannot provide both a color and a decoration to a Container

Issue

every time that i restart the code to check app , i have an error that say Cannot provide both a color and a decoration , the color argument is just a short hand for "decoration : new Boxdecoration( color : color ) "
maybe its true and i have a mistake but its doesn’t say where is it?
when i delete something like font size , a widget or something that has not any correlate to error , and reload the app , app start without any problem or error that show…


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),
      ],
    );
  }
} ```

Solution

Try to add color inside decoration like this:

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

This will definitely help you

Answered By – littleironical

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *