Hello Guys How are you all? Hope You all are fine. Sometimes we have to pass data between two screens Especially we need to pass data when we navigate the screen. So today Here I come with a tutorial on How to Pass Data to a Stateful Widget in Flutter?
Without Wasting your Time Lets start this tutorial.
How to Pass Value From One Screen to Another Screen Using Navigator in Flutter ?
- How to Pass Data From One Screen to Another Using Navigator In Flutter
To pass data to another screen then just declare parameters to the second screen using the constructor. Then you can easily access this parameter using widget.yourParameter in your second screen. Just Follow Below Tutorial.
- Pass Data From One Screen to Another Using Navigator In Flutter
To pass data to another screen then just declare parameters to the second screen using the constructor. Then you can easily access this parameter using widget.yourParameter in your second screen. Just Follow Below Tutorial.
To pass data to another screen then just declare parameters to the second screen using the constructor. Then you can easily access this parameter using widget.yourParameter in your second screen. Just Follow Below Tutorial.
How to Pass Data From One Screen to Another Using Navigator In Flutter ?
1. Suppose I Have Screen Named LoginScreen When I am Login Into it. I Want To Redirect User To HomeScreen With Some Parameter Like Email.
2. So I Am Just Declaring Email Parameter In My HomeScreen Exact Like Below And Set parameters to State using it’s constructor.
class HomeScreen extends StatefulWidget {
final String email;
const HomeScreen(this.email);
@override
HomeScreenState createState() => HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {
}
3. Now I am Passing My Parameter In LoginScreen Navigator Exact Like Below.
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => App("[email protected]"),
),
);
4. Then I Can Access this email Parameter in my HomeScreenState Class As Like Below.
class HomeScreen extends StatefulWidget {
final String email;
const HomeScreen(this.email);
@override
HomeScreenState createState() => HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Text(widget.email); // Here you direct access using widget
}
}
Summery
So it’s all About All about How to Pass Value From One Screen to Another Screen Using Navigator in Flutter possible Methods. Hope this above all solution helped you a lot. Comment below Your thoughts and your queries. Comment Below your suggestion.
Check Out Below Article
- The argument type ‘PointerEvent’ can’t be assigned to the parameter type ‘PointerDownEvent
- How to Change Border Color of ElevatedButton in Flutter
- Flutter-Unable to find bundled Java version after updated android studio Arctic Fox(2020.3.1) on M1 Apple Silicon
- How to show/hide password in TextFormField in flutter?
- How to upload images and file to a server in Flutter?