Working with arguments
Some times you need to pass an initial values to your SimpleNotifier
or StateNotifier
in that cases you can sue the setArguments
method of your provider.
In the next example to create a new instance of LoginController we need a initial email value
Next you can use the ref
parameter of your callback generator to get the arguments
passed in the initState
method.
WARNING
If you are using ModalRoute.of(context)
in your build
method or in the routes
parameter of one MaterialApp
to get arguments
that was passed by
Navigator.push
, Navigator.pushName
, etc and next you use Navigator.pushNamedAndRemoveUntil
or Navigator.pushNameAndRemoveUntil
to navigate to a new Route removing multiples routes from the Stack the ModalRoute.of(context)
will rebuild the route before remove it and it could be a problem with a provider
because that could be recreated a disposed provider.
In that cases you could use the PageWithArguments
widget to avoid the recreation of a disposed provider.
Or you can create yourn own widget using PageWithArgumentsWidget
class.