Reputation: 93
I have homeScreen, which every another screen returns to it. and one of the screens have parameters from TextField, which I need in the homeScreen, how I can navigate these parameters to the home? NOTE: when I use constructor, the other screens show an error in the line that navigate to Home because there is no parameters.
Upvotes: 0
Views: 466
Reputation: 599
You can pass data using parameters
class XYZ extends StatelessWidget {
final TextEditingController textController = TextEditingController();
void navigationFunction() {
//send the data from XYZ to HomePage
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage(textValue: textController.text)),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({this.textValue});
final String textValue; //use this textValue in HomePage
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
Upvotes: 0
Reputation: 3548
You can either use an optional parameter in your constructor:
Homepage({String textfield});
and use it on your Homepage (don't forget that this value is nullable)
Or you need to use some kind of state management with ValueNotifiers
Upvotes: 1