I was trying to get data from firestore using class defined like this one:
Future<QuerySnapshot<Map<String, dynamic>>> getPubs() async {
queryPubs = await pubsDb.get();
if (queryPubs!.docs.isEmpty) {
log("[getPubs] Variable queryPubs is empty");
} else {
await pubData(queryPubs!.docs).then((value) {
if (value.isNotEmpty) {
isPub.value = true;
log("[getPubs] Variable pubAll is not empty");
} else {
log("[getPubs] Variable pubAll is empty");
}
});
}
return queryPubs!;
}
Future<List<Map<String, dynamic>>> pubData(List<DocumentSnapshot>? docs) async {
for (int i = 0; i < docs!.length; i++) {
DbPublisher dbPublisher = DbPublisher.fstoreInfo(docs[i]);
final imgUrl = await getImgUrl(dbPublisher.imgName, DataType.PUBLISHER);
pubInfo = {
"name": dbPublisher.name,
"imgURL": imgUrl,
"imgName": dbPublisher.imgName,
"desc": dbPublisher.desc,
"email": dbPublisher.email,
"active": dbPublisher.active,
"status": dbPublisher.status,
"albums": dbPublisher.albums,
"songs": dbPublisher.songs,
"state": dbPublisher.state,
"privilege": dbPublisher.privilege,
"payout": dbPublisher.payout,
"compensation": dbPublisher.compensation,
"started": dbPublisher.started,
"due": dbPublisher.due,
"license": dbPublisher.license,
"duration": dbPublisher.duration,
"valid": dbPublisher.valid,
};
pubAll!.add(pubInfo);
}
return pubAll!;
}
I get the data, but when I was about to add one more data; the new data doesn't get displayed. Instead, it was previous data and there were redundant of that. I used the latest package of firestore. Did someone ever experience this one? I used GetX dependency injection for all of this. I used GetxService as it made it as permanent.
Update: redundant here I meant there is the same data over and over. But when I restarted the app, all the data return normal as it used to be. I wonder what is going on?
Update: The flutter code
Expanded(
child: FutureBuilder<QuerySnapshot<Map<String, dynamic>>>(
future: dNd.getPubs(),
builder: (context, AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) {
listAlbs = snapshot.data!.docs;
if (listAlbs.isNotEmpty) {
totalAlbs = listAlbs.length;
log("Load $totalAlbs albums from Firestore");
return ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
physics: const ScrollPhysics(),
controller: scrollCtrl,
itemCount: listAlbs.length,
itemBuilder: (context, index) {
return albsFstore(context, dNd.pubAll![index], index);
},
);
} else {
return const Center(child: FavText("The album data is empty", 15.0));
}
} else if (snapshot.hasError) {
return const Center(child: FavText("The server is error", 15.0));
} else {
return const Center(child: FavText("The data is empty", 15.0));
}
} else if (snapshot.connectionState == ConnectionState.waiting) {
return AlignPositioned(
dx: 0,
dy: -(MediaQuery.of(context).size.height / 4),
child: Container(
width: 128,
height: 128,
padding: const EdgeInsets.all(8.0),
decoration: const BoxDecoration(borderRadius:
BorderRadius.all(Radius.circular(16.0)), color: Color.fromARGB(88, 44, 44, 44)),
child: const LoadingIndicator(indicatorType: Indicator.ballRotateChase, colors: rainbowColors),),);
}
return const SizedBox();
},
),
),