Я хочу прочитать данные из моей облачной БД пожарного хранилища с помощью логического оператора ИЛИ. Я читал некоторые другие сообщения о том, как сделать это с Stream
слиянием, как в ЗДЕСЬ , но, похоже, все еще не выполняеттрюк, поскольку он просто возвращает только один поток и ошибку.Я хочу использовать данные, возвращенные в StreamBuilder
.до сих пор я пробовал это
Stream<List<QuerySnapshot>> getData() {
Stream<QuerySnapshot> stream1 = Firestore.instance.collection('htTwo').document('users')
.collection('userdata').document('all_').collection('personal_').where('myUID', isEqualTo: 'yrUID').snapshots();
Stream<QuerySnapshot> stream2 = Firestore.instance.collection('htTwo').document('users')
.collection('userdata').document('all_').collection('personal_').where('othersUID', isEqualTo: 'some123Giberish').snapshots();
return StreamZip([stream1, stream2]).asBroadcastStream();
}
// В StreamBuilder ...
StreamBuilder(
stream: getData(),
builder:(BuildContext context, AsyncSnapshot<List<QuerySnapshot>>snapshot){
if(!snapshot.hasData )return CupertinoPageScaffold(
child: Theme(
data:theme.copyWith(
accentColor: Colors.red,
inputDecorationTheme: InputDecorationTheme()),
child:Center(child:CircularProgressIndicator() ,)
),
);
int lengthOfDocs=0;
int querySnapShotCounter = 0;
snapshot.data.forEach((snap){lengthOfDocs = lengthOfDocs + snap.documents.length;});
int counter = 0;
return ListView.builder(
itemCount: lengthOfDocs,
itemBuilder: (_,int index){
try{DocumentSnapshot doc = snapshot.data[querySnapShotCounter].documents[counter];
counter = counter + 1 ;
return new Container(
child:ListTile(
title: Text(doc.data["othersUID"]),
subtitle: Text("${doc.data["myUID"]} :"),
)
);
}
catch(RangeError){
querySnapShotCounter = querySnapShotCounter+1;
counter = 0;
DocumentSnapshot doc = snapshot.data[querySnapShotCounter].documents[counter];
counter = counter + 1 ;
return new Container(child: Text(doc.data["othersUID"]));
}
},
);
},
),
);
}
}
// ошибка
I / флаттер (3939): Было сгенерировано следующее RangeError:
I / flutter (3939): RangeError (index): Неверное значение: Не в диапазоне 0..1, включительно: 2