Happy
Happy

Reputation: 121

Return data from a screen

I have two screens. I want a number to be returned from the second screen.

Navigator.pop(context, numder )

How can I make a handler on the first screen?

Upvotes: 0

Views: 63

Answers (1)

eamirho3ein
eamirho3ein

Reputation: 17900

you need to push like this when you want to receive data from next screen:

onPressed: ()async {
    var result = await Navigator.of(context).push(MaterialPageRoute(builder: (context) => NewScreen()));
    
    if(result != null){
       print(result);
    }
}

by say like this way, I mean call await can return to a variable, not exactly this push.

Upvotes: 1

Related Questions