flutter
flutter

Reputation: 6786

how to distinguish between paths to the same screen in flutter?

The user has 2 ways to get to the same screen in my app. The navigation for one of the ways involves passing a variable to this screen. The other path to the screen doesn't pass anything. I was going to check if the variable I pass is null but I'm not sure if that's the best(what if the variable is null from the screen that passes a variable). Any suggestions?

Upvotes: 0

Views: 74

Answers (2)

Shady Boshra
Shady Boshra

Reputation: 2931

You can send another parameter, its type is bool, so you can send true if user navigated using first way, and false if user navigated using second way.

And then check it. In this case even if it was sent as null, you are sure determined by using bool parameter.

Upvotes: 1

Shriya Pandya
Shriya Pandya

Reputation: 432

You don't need to pass anything from other screen, But you should check null prior in the screen where you are using that variable.

Upvotes: 0

Related Questions