skip to Main Content

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

3

Answers


  1. You seem to have set a decoration already, so drop the color: color,, because it’s not suported to do both.

    Login or Signup to reply.
  2. 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),
      ),
    
    Login or Signup to reply.
  3. 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),
      ),
    );
    

    }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search