title: How do you set TextField text to text received from JSON file? (Flutter)
body: <p>I am pretty new to flutter and I was wondering how I could set the the TextField text using a <code>TextEditController</code> (named crText) to a text received from a JSON file. The text from the JSON file is stored in chemText which is a String. The <code>getData</code> method, which has all the querying functions is called during an <code>onPressed</code> method in the "Search" icon. The text in the TextField is desired to be changed using "controller: " which is set to crText. The goal here is to set crText to chemText (which holds the text from queryData variable (<code>json.decode(queryParams)</code>). The "controller: " can be found at the very end of the code segment.</p>
  
  <pre><code>import 'dart:ffi';
  import 'dart:io';
  
  import 'package:flutter/foundation.dart';
  import 'dart:convert';
  import 'dart:async';
  import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  
  
  class myClass extends StatelessWidget{
    var crText = TextEditingController();
    String chemText;
  
    var queryParameters = {
      "ID" :  "nfuiwnfuiwnfuinfuwnfuinw" //just one of the hashes (example)
    };
  
  
    Future&lt;String&gt; getData() async{
  
  
      var uri =
      Uri.https('www.myUrl.com', 'api/parameters', queryParameters);
  
      Icon searchIcon = Icon(Icons.search);
      var objMapUrl = "https://myUrl.com";
      Map data;
      Map queryData;
      http.Response response  = await http.get(
          Uri.encodeFull(objMapUrl),
          headers: {
  
            "key" : "ifhfi2jfowjefounf893f"
          }
      );
  
      var queryParams = await http.get(uri, headers: {
        "key" : "ifhfi2jfowjefounf893f"
  
      });
  
      //data = json.decode(response.body);
  
      //print(data["hashes"]);
      // print( data["names"]);
      // print(data); //prints hashes
  
      //query parameters
  
      queryData = json.decode(queryParams.body);
      //print(queryData);
  
      chemText = queryData.toString();
      print(chemText);
  
      return chemText;
  
    }
  
    @override
    Widget build(BuildContext context) {
  
      return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          elevation: 0.0,
          automaticallyImplyLeading: false,
          title: Container(
            margin: EdgeInsets.symmetric(horizontal: 1.0, vertical: 8.0),
            decoration: BoxDecoration(
              color: Colors.lightBlueAccent,
              borderRadius: BorderRadius.all(Radius.circular(12.0)),
  
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: &lt;Widget&gt;[
                Expanded(
                  flex: 1,
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 5.0),
                    child: TextFormField(
  
                      textInputAction: TextInputAction.done,
                      onFieldSubmitted: (term){
                          getData();
                      },
                      cursorColor: Colors.white,
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        hintText: "Enter  Name",
                        hintStyle: TextStyle(color: Colors.white),
                      ),
                    ),
                  ),
                ),
                Expanded(
                  flex: 0,
                  child: Container(
                    padding: EdgeInsets.symmetric(horizontal: 0.0),
                    child: Row(
                      children: &lt;Widget&gt;[
                        IconButton(
                          onPressed: getData,
                          icon: Icon(Icons.search, color: Colors.white),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
        body: new Container(
          padding:  new EdgeInsets.fromLTRB(25.0, 200.0, 25.0, 0.0),
  
          child: Column(
            crossAxisAlignment: CrossAxisAlignment. center,
            children: &lt;Widget&gt;[
              new TextField(
                decoration: new InputDecoration(
                  border: const OutlineInputBorder(
                    borderSide: const BorderSide(
                      color: Colors.blueGrey, width: 2.0
                    )
                  )
                ),
               //textfield text needs to change to the text recieved from json.decode(queryParams.body) or chemText
               controller: crText,
                maxLines: 20,
  
              )
            ],
          ),
        ),
      );
    }
  
  }
  
  
  </code></pre>