PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 5, 2022

[FIXED] How to pass callback in Flutter

 July 05, 2022     callback, dart, flutter, pass-by-reference     No comments   

Issue

Code will explain all:

    class ResultOverlay extends StatefulWidget {
    
      final bool _isCorrect;
      VoidCallback _onTap;
    
      ResultOverlay(this._isCorrect, this._onTap);
      ......
      ......
}

Its state class:

class ResultOverlayState extends State<ResultOverlay>{
@override
  Widget build(BuildContext context) {
    ........
      child: new InkWell(
        onTap: () => widget._onTap,
.....
.....
}

Passing of callback function:

new ResultOverlay(isCorrect, () {
                        () => CallAnswerPage();
                      })

What I am missing here?


Solution

I was not passing the callback correctly. Here is the correct syntax:

new ResultOverlay(
    isCorrect, 
    () => callAnswerPage()
)

So silly mistake :)



Answered By - pallav bohara
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing