I have this method with onTap parameter
myFunc({onTap}){
return onTap;
}
then, I need to use it like this
myFunc(
onTap: print('lorem ipsum');
)
How I can make it correctly? thanks
Implementation Step 1: Add Firebase to Flutter Add Firebase to your Flutter app | Firebase Follow this guide to add Firebase products to a Flutter app. Firebase supports frameworks like Flutter on a best-effort… firebase.google.com Step 2: Add the dependencies Add dependencies to pubspec. yaml file.
Callback is basically a function or a method that we pass as an argument into another function or a method to perform an action. In the simplest words, we can say that Callback or VoidCallback are used while sending data from one method to another and vice-versa.
VoidCallback = void Function() Signature of callbacks that have no arguments and return no data.
A custom callback function can be created by using the callback keyword as the last parameter. It can then be invoked by calling the callback() function at the end of the function. The typeof operator is optionally used to check if the argument passed is actually a function. console.
You can do like below. Note that you can specify parameter or avoid and I have added Function
(You can use ValueChange, Voidcallback)
myFunc({Function onTap}){
onTap();
}
//invoke
myFunc(onTap: () {});
If you want to pass arguments:
myFunc({Function onTap}){
onTap("hello");
}
//invoke
myFunc(onTap: (String text) {});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With