I'm making a bool condition for search and review cart page then i face these 3 errors i try to solve but not success(first 2 error on container //Expected to find ','. //The element type 'bool' can't be assigned to the list type 'Widget'. )and the second one on the text widget(Expected to find ']'.)
bool isBool = false;
SigleItem(this.isBool);
isBool ==false Container( //Expected to find ','. //The element type 'bool' can't be assigned to the list type 'Widget'.
margin: const EdgeInsets.only(right: 15),
padding: const EdgeInsets.symmetric(horizontal: 10),
height: 35,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
const Expanded(
child: Text(
'RS-799',
style: TextStyle(
color: Colors.grey,
),
),
),
Center(
child: Icon(
Icons.arrow_drop_down,
size: 20,
color: primaryColor,
),
),
],
),
):Text('750')//Expected to find ']'.
CodePudding user response:
You forgot the question mark after bool condition, read
CodePudding user response:
You forgot the use question mark. You need to use like this.
isBool == false ? Container(
margin: const EdgeInsets.only(right: 15),
padding: const EdgeInsets.symmetric(horizontal: 10),
height: 35,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
const Expanded(
child: Text(
'RS-799',
style: TextStyle(
color: Colors.grey,
),
),
),
Center(
child: Icon(
Icons.arrow_drop_down,
size: 20,
color: primaryColor,
),
),
],
),
):Text('750'),
CodePudding user response:
You can directly use ternary operator like this
isBool ? text("if true then show this") : text("if false then show this)
boool_var ? true_widget : false_widget