0

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?

dxx
  • 3
  • 1

2 Answers2

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

testFunction(){
    myPlacement.requestContent;
}

use bracket for the testFunction

Yunus Kocatas
  • 286
  • 2
  • 9
  • Yes! I was reading and found that is not the same to call a function with or without brackets. Without brackets you are not calling the funcion, you are referencing it. Am I right? – dxx Jan 07 '22 at 20:08
  • Actually, the trick was putting brackets inside de function: myPlacement.requestContent(); – dxx Jan 07 '22 at 20:11
  • did it worked for you – Yunus Kocatas Jan 07 '22 at 20:11
0

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().