Home > Back-end >  Set decoration for container in container
Set decoration for container in container

Time:09-24

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'[enter image description here][1]

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

CodePudding user response:

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]),
  ),
);
  • Related