I have set the AutoCompleteTextField but when I navigate from one page to the other also by sending & receiving the same entered value the value is not getting displayed in the AutoCompleteTextField. And also when I tap in the suggestions I'm getting an error

The getter 'controller' was called on null. Receiver: null Tried calling: controller

Code:

class CustomRegistration extends StatefulWidget {
final String pincodeC;
CustomRegistration([this.pincodeC])
  @override
  _CustomRegistrationState createState() => _CustomRegistrationState();
}

class _CustomRegistrationState extends State<CustomRegistration> {
FocusNode pincodeFocus = new FocusNode();
TextEditingController pincode = new TextEditingController();
List<String> suggestionList = ['170010','110011','170001'];
SimpleAutoCompleteTextField textField;

  @override
  Widget build(BuildContext context) {

     Column body = new Column(children: [
      new ListTile(
        title: textField,)
    ]);
    body.children.addAll(added.map((item) {
      return new ListTile(title: new Text(item));
    }));

    print(textField); 

    return Scaffold(
     body: Builder(
        builder: (context) => SingleChildScrollView(
          child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                 AutoCompleteTextField(
                              focusNode: pincodeFocus,
                              decoration: InputDecoration(
                                border: InputBorder.none,
                                prefixIcon: Icon(Icons.home),
                                hintText: "Pincode",
                              ),
                              controller: pincode,
                              itemSubmitted: (item) {
                                setState(() {
                                  textField.controller.text = item.toString();
                                  print('item submitted' + item.toString());
                                });
                              },
                              key: key,
                              suggestions: suggestionList,
                              itemBuilder: (context, item){
                                return Container(
                                  padding: EdgeInsets.all(20.0),
                                  child: Row(
                                    children: <Widget>[
                                      Text(
                                        item,
                                        style: TextStyle(color: Colors.black),
                                      )
                                    ],
                                  ),
                                );
                              },
                              itemSorter: (a, b) {
                                return a.compareTo(b);
                              },
                              itemFilter: (item, query) {
                                return item
                                    .toLowerCase()
                                    .toString()
                                    .startsWith(query.toLowerCase());
                              },
                            ),
                          ]))));}}

When I'm printing the textfield I get null and where to initialize the widget.pincodeC ?


Solution 1: Niroop Nife

Thank you all for your kind assistance, i did get the result by adding pincode.text = widget.pincodeC; inside build