Controller returning results for another controller - Flutter (Dart)

42 views Asked by At

I want to search for places using Google Maps API and when I search for a place there is a small widget that appears with all the suggestions for the places relative to that what you just searched. I have two controllers that should be returning results for places (Google Maps API) but the second Controller is returning results for the first Controller. Picture for better understanding:

enter image description here

The second controller is returing results for the first controller, which is not what I want

Code:

  bool _fromListVisible = false;
  bool _toListVisible = false;

//this code is just for the small widget 
//that appears and disappears when you click on a place 
//(the suggestion for the places)
Row(
            children: [
              Expanded(
                child: Stack(
                  children: [
                    Column(
                      // mainAxisSize: MainAxisSize.min,
                      children: [
                        // from Controller code
                        TextFormField(
                          controller: controllerProvider.fromController,
                          decoration: InputDecoration(hintText: "Origin"),
                          onChanged: (value) {
                            // print(value);
                            Provider.of<ControllerProvider>(context,
                                listen: false);
                            setState(() {
                              _fromListVisible = true;
                            });
                          },
                        ),
                        if (_fromListVisible &&
                            controllerProvider.fromController.text.isNotEmpty)
                          Stack(children: [
                            Visibility(
                              visible: _fromListVisible,
                              child: Container(
                                height: 200,
                                child: ListView.builder(
                                  itemCount: _placesList.length,
                                  itemBuilder: ((context, index) {
                                    return ListTile(
                                      title: Text(
                                          _placesList[index]['description']),
                                      onTap: () {
                                        controllerProvider.fromController.text =
                                            _placesList[index]['description'];
                                        _fromListVisible = false;
                                      },
                                    );
                                  }),
                                ),
                              ),
                            ),
                          ]),
                        // to Controller code
                        TextFormField(
                          controller: controllerProvider.toController,
                          decoration: InputDecoration(hintText: "Destination"),
                          onChanged: (value) {
                            // print(value);
                            Provider.of<ControllerProvider>(context,
                                listen: false);
                            setState(() {
                              _toListVisible = true;
                            });
                          },
                        ),
                        if (_toListVisible &&
                            controllerProvider.toController.text.isNotEmpty)
                          Stack(children: [
                            Visibility(
                              visible: _toListVisible,
                              child: Container(
                                height: 200,
                                child: ListView.builder(
                                  itemCount: _placesList.length,
                                  itemBuilder: ((context, index) {
                                    return ListTile(
                                      title: Text(
                                          _placesList[index]['description']),
                                      onTap: () {
                                        controllerProvider.toController.text =
                                            _placesList[index]['description'];
                                        setState(() {
                                          _toListVisible = false;
                                        });
                                      },
                                    );
                                  }),
                                ),
                              ),
                            ),
                          ]),
                      ],
                    ),
                    Positioned(//icon),
                  ],
                ),
              ),
            ],
          ),
0

There are 0 answers