flutterdarttapjoy

Flutter onPressed - Difference between using a function or make a direct call


I am playing with Tapjoy's offerwall, I just don't know why this works:

ElevatedButton(
            child: Text("request content for Placement 001"),
            onPressed: myPlacement.requestContent,
          ),

And then this doesn't:

ElevatedButton(
            child: Text("request content for Placement 001"),
            onPressed: testFunction,
),

testFunction(){
    myPlacement.requestContent;
}

As you can see it's the same code but instead of calling directly I use a function...

requestContent returns a Future. This function internally makes a http request that I can see log in the console for the first option. The second one nothing happens..

Any ideas?


Solution

  • This block of code will work

    ElevatedButton(
                child: Text("request content for Placement 001"),
                onPressed: testFunction, ),
    
    testFunction(){
        myPlacement.requestContent(); 
    }
    

    Use the bracket after myPlacement.requestContent inside the testFunction().