4

I have 2 CupertinoPicker inside BottomSheet, the data comes from Firestore when I am changing selected Item in governorate it updates the List data of locations in the another cupertinopicker

Here picture you will see 4 Cupertino picker in Row but the forth Picker doesn't update unless I close the bottom sheet and open it again so how to Update/Refresh CupertinoPicker List Data while onSelectedItemChanged() called

here is some Code

 Expanded(
              child: StreamBuilder(
                  stream: _fireStore.collection('Locations').snapshots(),
                  builder: (context, snapshot) {
                    if (!snapshot.hasData) {
                      return Container();
                    }
                    return CupertinoPicker(
                        squeeze: 1.5,
                        diameterRatio: 1,
                        useMagnifier: true,
                        looping: true,
                        scrollController: _controllerPicker,
                        itemExtent: 33.0,
                        backgroundColor: Colors.white,
                        onSelectedItemChanged: (int index) => setState(() {
                              _pickerKey.currentState.build(context);
                              _getChosenGovLocation(snapshot
                                  .data.documents[index].documentID);
                            }),
                        children: new List<Widget>.generate(
                            snapshot.data.documents.length, (int index) {
                          return new Center(
                            child: new Text(
                              '${snapshot.data.documents[index]['countryEN']}',
                              style: TextStyle(fontSize: 16),
                            ),
                          );
                        }));
                  }),
            ),
            Expanded(
              child: CupertinoPicker.builder(
                  key: _pickerKey,
                  squeeze: 1.5,
                  diameterRatio: 1,
                  useMagnifier: true,
                  scrollController: new FixedExtentScrollController(
                    initialItem: 0,
                  ),
                  itemExtent: 33.0,
                  backgroundColor: Colors.white,
                  onSelectedItemChanged: (int index) {
                    setState(() {
                      sortLocation = _sortBranches[index]['branchEN'];
                    });
                    print(sortLocation);
                  },
                  childCount: _sortBranches.length,
                  itemBuilder: (context, index) {
                    return new Center(
                      child: new Text(
                        '${_sortBranches[index]['branchEN']}',
                        style: TextStyle(fontSize: 16),
                      ),
                    );
                  }),
            ),

and here is the Method that called while the selecte item changing

   _getChosenGovLocation(id) {
    _sortBranches.clear();

    _fireStore.collection('Locations').document(id).snapshots().forEach((doc) {
      setState(() {
        _sortBranches = doc.data['branches'].toList();

        print(_sortBranches.length);
      });
    });

    print('list Called');
  }

1 Answers1

2

I've Fixed it out just used StatefullBuilder it fixed the problem