I have a line contains 4 outlinedbuttons and i have 4 widgets ( listview , ListWheelScrollView ,image png and svg image ) i want to display one widget only when i pressed at one outlinedbutton . what should i use for do this in flutter?
provide some code will be helpfull
Container(
padding: EdgeInsets.all(8.0),
height: 100,
child: Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () =>
//show widget1
)),
Expanded(
child: OutlinedButton(
onPressed: () =>
//show widget2
)),
Expanded(
child: OutlinedButton(
onPressed: () =>
//show widget3
)),
Expanded(
child: OutlinedButton(
onPressed: () =>
//show widget4
)),
],
),
)
3
Answers
You can do it in different ways.. A simple one would be creating 4 boolean variables for each widget. On pressing button true value for particular widget and false other 3 values. On the otherside, use if(isthiswidget) to display widget if value is true. some demo of code
onpressing widget1
onpressing widget2
do same for other functions
in UI set condition before every widget
note: use setstate, provider or any other statemanagement method to update realtime values and UI
create this var to identify which widget to show, it will get value from 0 to 3
and in onPressed of each button add this, don’t forget to add correct num
and use visibility to show widget
Create enum
Global variable for updating the value.
Widget
}
Set the enum value for updating Widget visibility.