错误:不能同时提供颜色和装饰。使用"装饰:BoxDecoration(颜色:彩色)"包:颤振/src/widget/容器。dart':断言失败:行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;
});
},
),
),
当您使用BoxDecoration()
时,请记住将颜色参数放在BoxDecoration()
中。
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), // <= No more error here :)
color: Colors.red,
),
height: 100,
child: Text(listTmp[index]),
),
);
永远记住,当你使用BoxDecoration来装饰容器时,使用BoxDecoration内部的color属性,
否则,您将面临错误
正确的方法!
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(078),
color: Colors.red,
),
child: Text('text'),
),
);
错误的方法…!
Container(
color: Colors.red,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(078),
),
child: Text('text'),
),
);