Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 如何在listview Flatter中显示firestore中的图像数组?_Image_Flutter_Listview_Google Cloud Firestore - Fatal编程技术网

Image 如何在listview Flatter中显示firestore中的图像数组?

Image 如何在listview Flatter中显示firestore中的图像数组?,image,flutter,listview,google-cloud-firestore,Image,Flutter,Listview,Google Cloud Firestore,我想在listview中显示从firestore读取数据的图像。我将属性库映像声明为数组类型。这是我的集合。 当我运行代码时,图像只显示数组的第一个索引,第二个将像这样读取数组的第一个索引。假设是图像的第二张幻灯片,它将显示firestore中数组的第二个索引。 这是我的密码 import 'package:carousel_pro/carousel_pro.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; impor

我想在listview中显示从firestore读取数据的图像。我将属性库映像声明为数组类型。这是我的集合。

当我运行代码时,图像只显示数组的第一个索引,第二个将像这样读取数组的第一个索引。假设是图像的第二张幻灯片,它将显示firestore中数组的第二个索引。

这是我的密码

import 'package:carousel_pro/carousel_pro.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:fyp/shared/Loading.dart';
import 'package:google_fonts/google_fonts.dart';

class ListTask extends StatefulWidget {
  @override
  _ListTaskState createState() => _ListTaskState();
}


final FirebaseAuth auth = FirebaseAuth.instance;
Stream<QuerySnapshot> getUserRd(BuildContext context) async* {
  final FirebaseUser rd = await auth.currentUser();
  yield* Firestore.instance.collection("Task").where('uid',isEqualTo: rd.uid).snapshots();
}

class _ListTaskState extends State<ListTask> {
  List<NetworkImage> _listOfImages = <NetworkImage>[];
  @override
  Widget build(BuildContext context) {
    return Container(
      child: StreamBuilder(
          stream: getUserRd(context),
          builder: (context, snapshot){
            if (snapshot.hasError || !snapshot.hasData) {
              return Loading();
            } else{
              return ListView.builder(
                  itemCount: snapshot.data.documents.length,
                  itemBuilder: (BuildContext context, int index){
                    DocumentSnapshot ba = snapshot.data.documents[index];
                    _listOfImages =[];
                    for(int i =0; i < snapshot.data.documents[index].data['url'].length; i++){
                      _listOfImages.add(NetworkImage(snapshot.data.documents[index].data['url'][i]));
                    }
                    return Card(
                        child:ListTile(
                          title: Container(
                            alignment: Alignment.centerLeft,
                            child: Column(
                              children: <Widget>[
                                SizedBox(height: 5.0),
                                Container(alignment: Alignment.centerLeft,
                                  child: Row(
                                    children: [
                                      Text("Sumber Aduan: ", style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                      Text(ba['sumberAduan'], style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                    ],
                                  ),
                                ),
                                SizedBox(height: 5.0),
                                Container(alignment: Alignment.centerLeft,
                                  child: Row(
                                    children: [
                                      Text("Nombor Aduan: ", style: GoogleFonts.lato(fontWeight: FontWeight.bold)),
                                      Text(ba['noAduan'], style: GoogleFonts.lato(fontWeight: FontWeight.bold)),
                                    ],
                                  ),
                                ),
                                SizedBox(height: 5.0),
                                Container(alignment: Alignment.centerLeft,
                                  child: Row(
                                    children: [
                                      Text("Status: ", style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                      Text(ba['verified'], style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                    ],
                                  ),
                                ),
                                Column(
                                  children: [
                                    Container(
                                      margin: EdgeInsets.all(10.0),
                                      height: 200,
                                      decoration: BoxDecoration(
                                          color: Colors.white
                                      ),
                                      width: MediaQuery.of(context).size.width,
                                      child: Carousel(
                                        boxFit: BoxFit.cover,
                                        images: _listOfImages,
                                        autoplay: false,
                                        indicatorBgPadding: 5.0,
                                        dotPosition: DotPosition.bottomCenter,
                                        animationCurve: Curves.fastLinearToSlowEaseIn,
                                        animationDuration: Duration(milliseconds: 2000),
                                      ),
                                    )
                                  ],
                                )
                              ],
                            ),
                          ),
                            onTap: () {listAddress(ba['id']);}
                        )
                    );
                  });
              }
           }),
    );
  }
  void listAddress(String id) {
    showModalBottomSheet(
        shape: RoundedRectangleBorder(
            borderRadius: new BorderRadius.only(
                topLeft: const Radius.circular(10.0),
                topRight: const Radius.circular(10.0)
            )
        ),
        context: context,
        builder: (builder){
          return StreamBuilder(
              stream:Firestore.instance.collection("Task").document(id).snapshots(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Loading();
                } else {
                        return Container(
                          height: 150,
                          child: Container(
                            padding: EdgeInsets.fromLTRB(20.0, 3, 30.0, 5.0),
                            child: Column(
                                children: <Widget>[
                                  Row(
                                    children: <Widget>[
                                      Align(
                                        alignment: Alignment.topLeft,
                                        child: Column(
                                          crossAxisAlignment: CrossAxisAlignment.start,
                                          children: [
                                            Container(
                                              alignment: Alignment.topLeft,
                                              width: 220,
                                              margin: EdgeInsets.only(top:26, left: 14),
                                              child: Row(
                                                children: [
                                                  Text("Kawasan: ", textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                                  Text( snapshot.data['kawasan'], textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                                ],
                                              ),
                                            ),
                                            Container(
                                              width: 220,
                                              margin: EdgeInsets.only(top:4, left: 15),
                                              child: Row(
                                                children: [
                                                  Text("Nama Jalan :", textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                                  Text(snapshot.data['naJalan'], textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                                ],
                                              ),
                                            ),
                                            Container(
                                              width: 220,
                                              margin: EdgeInsets.only(top:4, left: 15),
                                              child: Row(
                                                children: [
                                                  Text("Kategori : ", textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                                  Text(snapshot.data['kategori'], textAlign: TextAlign.left,style: GoogleFonts.asap(fontWeight: FontWeight.bold)),
                                                ],
                                              ),
                                            ),
                                          ],
                                        ),
                                      )
                                    ],
                                  ),
                                ],
                              ),
                          ),
                          );
                      }
                 }
            );
        }
    );
  }
}
import'包:carousel_pro/carousel_pro.dart';
导入“包:cloud_firestore/cloud_firestore.dart”;
导入“包:firebase_auth/firebase_auth.dart”;
进口“包装:颤振/材料.省道”;
导入“package:flatter/rendering.dart”;
导入“包:fyp/shared/Loading.dart”;
导入“package:google_fonts/google_fonts.dart”;
类ListTask扩展StatefulWidget{
@凌驾
_ListTaskState createState()=>\u ListTaskState();
}
final FirebaseAuth auth=FirebaseAuth.instance;
流getUserRd(BuildContext上下文)异步*{
final FirebaseUser rd=wait auth.currentUser();
yield*Firestore.instance.collection(“任务”).where('uid',isEqualTo:rd.uid).snapshots();
}
类_ListTaskState扩展状态{
列表_listOfImages=[];
@凌驾
小部件构建(构建上下文){
返回容器(
孩子:StreamBuilder(
流:getUserRd(上下文),
生成器:(上下文,快照){
if(snapshot.hasrerror | | |!snapshot.hasData){
返回加载();
}否则{
返回ListView.builder(
itemCount:snapshot.data.documents.length,
itemBuilder:(构建上下文,int索引){
DocumentSnapshot ba=快照.数据.文档[索引];
_listOfImages=[];
对于(int i=0;i