Closed robman70 closed 2 years ago
Yo @robman70, if your onPress
function doesn't take any arguments, then change the parameter type of onPress
fn in questionDialog
to Function()
or VoidCallback
i.e.
static questionDialog(BuildContext context, String title, String text, Function() onPress) async {
or
static questionDialog(BuildContext context, String title, String text, VoidCallback onPress) async {
@OutdatedGuy, thank you for your response but unfortunately none of your solutions worked for me
@OutdatedGuy , sorry... my error:
static questionDialog(BuildContext context, String title, String text, Function() onPress) async {
worked perfectly.
Thank you!
Using the current version (2.2.1), VS Code shows an error: "The argument type 'Function' can't be assigned to the parameter type 'dynamic Function()?" (refers to 'btnOkOnPress: onPress'), so I tried to modify the function declaration:
static questionDialog(BuildContext context, String title, String text, Function onPress) async { await AwesomeDialog( ... (no changes)... btnOkOnPress: () async => onPress, ).show(); }
The error disappeared, but the code inside 'onPress' does not run.
Btw, I just realized that here you aren't calling the function onPress
but just returning it. It should have been like this instead.
static questionDialog(BuildContext context, String title, String text, Function onPress) async {
await AwesomeDialog(
... (no changes)...
btnOkOnPress: () => onPress(),
).show();
}
or
static questionDialog(BuildContext context, String title, String text, Function onPress) async {
await AwesomeDialog(
... (no changes)...
btnOkOnPress: () {
onPress();
},
).show();
}
Yes. Now (thanks to your previous tip) it just works with:
static questionDialog(BuildContext context, String title, String text, Function() onPress) async {
await AwesomeDialog(
...
btnOkOnPress: onPress,
).show();
}
I have a problem passing a function to btnOkOnPress.
In a previous version (2.1.3) I could use this code:
Then, inside a button, I called the previous function:
And all worked perfectly.
Using the current version (2.2.1), VS Code shows an error: "The argument type 'Function' can't be assigned to the parameter type 'dynamic Function()?" (refers to 'btnOkOnPress: onPress'), so I tried to modify the function declaration:
The error disappeared, but the code inside 'onPress' does not run.
What am I doing wrong?
Thanks in advance