Reputation: 643
I'm not sure if this is possible or not, What I am looking to do is remove a container if the switch is in the ON position and reappear the container in the OFF position. I created the switch and the container inside a stateful widget. the code is below.
Container(
color: Colors.yellow,
child: Center(
child: Switch(value: ads,
onChanged: (value){
setState(() {
ads = value;
print(value);
});
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
),
),
),
Padding(padding: EdgeInsets.fromLTRB(100.0, 0.0, 5.0, 10.0)),
Container(
color: Colors.red,
child: Text("Remove the red container if switch is ON"),
),
A image of the following is below
Any help would be appreciated.
Upvotes: 0
Views: 185
Reputation: 4763
Replace your Container
section with the following
!ads ? Container(
color: Colors.red,
child: Text("Remove the red container if switch is ON"),
) : SizedBox(),
Upvotes: 1