I'm to trying to get images from firestore database and put onto String type list and want to show as the slider Image.
(我要尝试从Firestore数据库获取图像并将其放到“字符串类型”列表中,并希望显示为滑块图像。)
but the above error is occurring on Screen but after milliseconds, error goes and images show as slider (但是上述错误发生在屏幕上,但是在毫秒后,错误消失了,图像显示为滑块)
Decleared Global Varible:
(已清除的全局变量:)
List<String> getSliderImages=[];
Method for fetched images from firestore:
(从消防站中获取图像的方法:)
And this method is calling inside initState()
method
(而且此方法在initState()
方法内部进行调用)
void getSliderImage(){
List<String> userId=[];
Firestore.instance.collection("Slider").getDocuments()
.then((QuerySnapshot snapshot) {
snapshot.documents.forEach((f){
setState(() {
userId.add(f.documentID);
});
});
for(int i=0;i<userId.length;i++){
setState(() {
print('snap.documentID_IF_userId :${userId[i]}');
Firestore.instance.collection('Slider').document(userId[i]).get().then((DocumentSnapshot document){
String image=document['Image'];
getSliderImages.add(image);
print('snap.documentID_IF_userId_IMAGE :$image');
print("getSliderImages:$getSliderImages");
});
});
}
}).catchError((onError){
print(onError);
setState(() {
Fluttertoast.showToast(msg: "$onError");
});
});
}
Slider widget, there I want to display images:
(滑块小部件,我要在其中显示图像:)
Here I used carousel_pro plugin for Slider
(在这里我使用了carousel_pro滑块)
Container(
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
//color: Colors.black
),
height: MediaQuery.of(context).size.height/5,
width: MediaQuery.of(context).size.height/2,
child: Carousel(
images: [
new NetworkImage(getSliderImages[0]),
new NetworkImage(getSliderImages[1]),
new NetworkImage(getSliderImages[2]),
new NetworkImage(getSliderImages[3]),
],//getSliderUserId
showIndicator: true,
borderRadius: true,
moveIndicatorFromBottom: 100.0,
noRadiusForIndicator: false,
overlayShadow: false,
overlayShadowColors: Colors.white,
overlayShadowSize: 0.7,
)
),
ask by Shruti Ramnandan Sharma translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…