I wanna define a function or something like that to make a new widget on my button press, Also, I wanna create that widget in a specific column. Anybody can help?
Asked
Active
Viewed 142 times
2 Answers
1
you can define bool variable to control show or hide that widget and in button onPressed method change that variable in setState.
something like this code:
var _showWidget = false;
void changeShow(){
setState(() {
_showWidget = !_showWidget;
});
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: _showWidget? Text('Show'): Text('Hide'),
onPressed: changeShow
),
if (_showWidget)
Container(
width: 150,
height: 50,
color: Colors.green,
child: Center(child: Text('Hello Word')),
),
],
),
);
}

Wehid Behrami
- 226
- 2
- 6
0
well you can basically use invisible and visible field in your widget i.e. the widget is already made and u can assign a function later to it ..ex when the button is pressed the widget becomes visible and you pass a function or value to it.

austin
- 517
- 5
- 16
-
It'll make a blank space, won't it? – M.Taha Basiri Aug 21 '20 at 12:15
-
i believe you are not using the correct syntax for what you want to achieve .if the widget is fetching data from a server u can try making a future builder for it , – austin Aug 21 '20 at 16:45