Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pass data and receive on textfield widget in Flutter

How to pass a data from first screen to second screen but should receive on textfield widget in second screen. I have tried but there is no option in textfield widget, how to do this?

TextField(
                                keyboardType: TextInputType.text,
                                decoration: InputDecoration(
                                    fillColor: Colors.white,
                                    hintText: "",
                                    filled: true,
                                    labelText: "First name",
                                    enabledBorder: OutlineInputBorder(
                                      borderSide: BorderSide(
                                          color: Colors.white),
                                      borderRadius: BorderRadius.circular(6),
                                    ),
                                    focusedBorder: OutlineInputBorder(
                                      borderSide: BorderSide(
                                          color: Colors.white),
                                      borderRadius: BorderRadius.circular(6),
                                    )),
                              ),

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To set default text in your TextField you need to use TextEditingController, you can use it by initializing in initState or directly to the TextField, here are the examples

To initialize with initState

  late TextEditingController _controller;
  
  @override
  void initState() {
    _controller.text = widget.text;
    super.initState();
  }

To pass value directly

TextField(
            controller: TextEditingController(text: widget.text),
            keyboardType: TextInputType.text,
            decoration: InputDecoration(
                fillColor: Colors.white,
                hintText: "",
                filled: true,
                labelText: "First name",
                enabledBorder: OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.white),
                  borderRadius: BorderRadius.circular(6),
                ),
                focusedBorder: OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.white),
                  borderRadius: BorderRadius.circular(6),
                )),
          )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading