gpt4 book ai didi

flutter - 如何在从另一个 Cupertino Picker 调用 onSelectedItemChanged() 时更新/刷新 CupertinoPicker 列表数据

转载 作者:行者123 更新时间:2023-12-03 03:39:46 25 4
gpt4 key购买 nike

我在BottomSheet中有2个CupertinoPicker,当我在省内更改所选项目时,数据来自Firestore,它会更新另一个cupertinopicker中的位置列表数据

Here picture您将在 Row 中看到 4 个 Cupertino Picker,但第四个 Picker 不会更新,除非我关闭底部工作表并再次打开它,因此如何在 onSelectedItemChanged() 调用时更新/刷新 CupertinoPicker 列表数据

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');
}

最佳答案

我已经修复它刚刚使用 StatefullBuilder它解决了问题

关于flutter - 如何在从另一个 Cupertino Picker 调用 onSelectedItemChanged() 时更新/刷新 CupertinoPicker 列表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57943996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com