How do I receive a variable or function within the Textformfield input without having to type and save to the list with Flutter?

Asked

Viewed 32 times

0

I need to insert a text inside the input so there is no need for typing, it was a way to edit the data stored in Firebase, when I edit the data, goes to an editing screen with the data in each input, for the user to edit or not, as you see fit. I’m not able to do this, always requires me to type some character, tried functions, variables, various forms and none succeeded. If anyone can give a different idea or a solution, I’d be grateful.

I declared a control for the name, that way:

TextEditingController _controleNome = new TextEditingController();

In addition to inserting it into the initState:

void initState(){
    super.initState();
    _controleNome.text = 'Teste';
}

                              Container(
                                width: 330,
                                height: 50,
                                  child: TextFormField(
                                  autofocus: true,
                                  cursorColor: Colors.brown,
                                  style: TextStyle(fontSize: 16.0, height: 1.5, color: Colors.brown),
                                  textAlign: TextAlign.left,
                                  controller: _controleNome,
                                  decoration: InputDecoration(
                                    labelText: 'Nome',
                                    labelStyle: TextStyle(color: Colors.brown, fontSize: 16.0, fontWeight: FontWeight.w700),
                                    isDense: true,
                                    contentPadding: EdgeInsets.all(2.0),
                                  ),
                                  onChanged: (text){
                                    editado = true;
                                    setState(() {
                                      _editaContato.nome = text;
                                    });
                                  },
                                ),
                              ),
  • Try initialValue: 'valor inicial'

  • It was the first alternative I used, but I need the controller, which also doesn’t work. Both the initialValue and a controller do not accept the initial text without adding something, requires you to write some more character, just so it saves in the list and in the database.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.