Set decoration for container in container

485

Whenever you use BoxDecoration() remember to put the color parameter inside the BoxDecoration().

child: Container(
  decoration: BoxDecoration(
  borderRadius: BorderRadius.circular(10), // <= No more error here :)
  color: Colors.red,
  ),
  height: 100,
  child: Text(listTmp[index]),
  ),
);
Share:
485
m4n0
Author by

m4n0

1x Engineer Feel free to down vote or comment on my answers so that I can update/delete the outdated ones. Send me an email - [email protected] for our next project.

Updated on January 01, 2023

Comments

  • m4n0
    m4n0 over 1 year

    Error: 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 274 pos 15: 'color == null || decoration == null'

    Container(
          height: 250,
          child: PageView.builder(
            controller: _pageController,
            itemCount: listTmp.length,
            itemBuilder: (context, index) {
              return Padding(
                padding: const EdgeInsets.only(left: 5, right: 5),
                child: Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10), // <= Error here
                  ),
                  height: 100,
                  child: Text(listTmp[index]),
                  color: Colors.red,
                ),
              );
            },
            onPageChanged: (index) {
              setState(() {
                _currentIndex = index;
              });
            },
          ),
        ),
    
  • Admin
    Admin over 2 years
    :)) I would like to have a container circular(10) inside an a container not circular. Thank you!
  • Shaan Mephobic
    Shaan Mephobic over 2 years
    I'm sorry, I don't catch what you mean. Did you try my answer?
  • Admin
    Admin over 2 years
    Oh..you put the color in container. Sorry I didn't realize. This code has run. Thank you so much! :))