Search code examples
flutterdartflutter-layoutflutter-form-builder

How can i send data to textfield in flutter


Hello i am reading a barcode and if the barcode reader i would like set up the input of the Textfield the the data that i read but i couldn't figured out how to do that here is my code

 TextField(
     textFieldData=readDataTurnString();
                keyboardType: TextInputType.emailAddress,
                textAlign: TextAlign.center,
                onChanged: (value) {},
                decoration: InputDecoration(hintText: 'Enter Your Public Key'),

              ),

Solution

  • You are do something like following:

    TextEditingController _controller = new TextEditingController();
    
    @override
    Widget build(BuildContext context) {
    ...
        child: TextField(controller: _controller),
    }
    
    

    You can later use the _controller to set the value of Textfield like this:

    _controller.text = "New Text Value";
    

    Does this solve your problem?