I am trying to pass function as a parameter in my custom widget:
_Btn(name: _btnOne, continueBtn: onClick(1)),
I made an onClick function in my main widget:
onClick(int i) {
switch(i){
case 1:{
print('hello');
}
break;
}
}
and my button widget:
class _Btn extends StatelessWidget {
final Function btn;
const _GreenBtn({
Key key,
this.btn
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
child: ElevatedButton(
child: Text('hello'),
style: ElevatedButton.styleFrom(
primary: Colors.white,
),
onPressed: () {
btn();
},
),
);
}
}
I am new to flutter, and I am not sure why its not working, if I am doing the next syntax than its ok:
_Btn(name: _btnOne, continueBtn: () => print('hello')),
thanks