Home > Back-end >  How to fill TextFormField with variable value from another sceen in Flutter
How to fill TextFormField with variable value from another sceen in Flutter

Time:10-30

well I want to fill TextFormField with variable value using flutter location packages, so the idea here is that I want a method to call that var and make it text in TextFormField

TextFormField(
                        decoration: InputDecoration(
                          border: const OutlineInputBorder(),
                          labelText: isRtl ? HardcodedTextArabic.strAddress2Text: HardcodedTextEng.strAddress2Text,
                          hintText: isRtl ? HardcodedTextArabic.strAddress1TextHint: HardcodedTextEng.strAddress1TextHint,
                        ),
                        

                        **// varibles are in getuserlocation sceen
                        controller: HomeController.latitude**)

CodePudding user response:

you can pass the value like an argument from the other screen like

Navigator.of(context).pushNamed(routeName, arguments...);

Or you can use a state manager to save the value and consume it in the other screen.

In the other screen you recover the value and preload the value in the controller using the initState as the follows:

  @override
  void initState() {
    super.initState();
    _textController.text = widget.value;
  }

I recomend you this cookbook to learn to pass parameters: https://docs.flutter.dev/cookbook/navigation/navigate-with-arguments

  • Related