call back in flutter

77

The declaration of VoidCallback is

typedef void VoidCallback();
That is the type of functions that can be called with zero arguments and which does not return a useful value. That does not seem to be what you want. It's not entirely clear what you do want since the program isn't syntactically valid, but would this work for you:

class MyClass { 
  static doSomething(int i) { /* ... */ }
  MyOtherClass myOtherClass = new MyOtherClass(doSomething);
}
class MyOtherClass {
  final void Function(int) callback;
  MyOtherClass(this.callback);
  void callCallaback() { callback(5); }
}
Here we define the type of the callback field to be the type of functions that can be called with one integer argument and which returns no useful value. The doSomething method has that type, so it can be assigned to callback.

You could also use a typedef to name the function:

typedef Int2VoidFunc = void Function(int);
// or: typedef void Int2VoidFunc(int arg);
class MyOtherClass {
  final Int2VoidFunc callback;
  MyOtherClass(this.callback);
  void callCallaback() { callback(5); }
}
The effect is exactly the same, it just allows you to use a shorter name for the function type, but that only really makes sense if you use it a lot.

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
flutter call back function how to use callback in flutter in flutter how to call back void function in flutter backend call flutter how to make a callback in flutter flutter make callback function flutter make callback press back call function in flutter flutter widget call function on back back button callback function in flutter call back from flutter flutter function when back invoke method for back flutter flutter callback on back pressed how to create back function in flutter flutter widget call on back call back function flutter as pa run function on get.back() flutter call back function in flutter call back value flutte5r how to use back function in flutter how to use callback in flutter how to create a call back function in flutter call back example flutter Get.back(result: ""); how to use result in flutter flutter call directly backend call back functions in flutter call back flutter call back function flutter function call back in flutter flutter pass callback to widget How to callback in flutter back end dart callback: flutter flutter widget callback function flutter back and forth flutter navigation back callbacks in flutter instance callback flutter calbback methode flutter flutter calback function CallbackAction button flutter button callback flutter what type of variable in void call back in flutter callback in flutter flutter call back function callback flutter flutter set callback how to create callback in flutter flutter callback back on device flutter page callback flutter how to call a function in flutter call in flutter how to get callback in flutter callback flutter onCallback flutter paramaterized callback flutter what is callback in flutter callback function flutter flutter callback function Voice Callback flutter call back in flutter
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source