I've seen many tutorials/forums/threads about uploading files and images to Firebase Storage, but is there a way to show a progress indicator when uploading data to Cloud Firestore?
i.e. I click the upload button and a progress indicator shows. The upload process is almost instantaneous, so I'd like to add a 2-3 second delay just to show a indication that something actually happened during this process and that it was completed successfully.
I'm currently using the flutter_bloc library to handle the uploads to Cloud Firestore.
Code on my widget-builder page:
onPressed: summaryDataList.length == 0
? null
: () {
//Submit data to firebase
BlocProvider.of<SummaryBloc>(context).add(
UploadSummaryToFirebase(date: fullDate),
);
//Other code
},
Upload code in SummaryBloc:
Stream<SummaryState> _uploadSummaryToFirebase(
UploadSummaryToFirebase event) async* {
List<Map<String, dynamic>> listOfOrders = [];
var currentState = this.state;
try {
if (currentState is SummaryListState) {
currentState.summaryDataList.forEach((summaryData) async {
listOfOrders.add(summaryData.toJson());
});
var ref = Firestore.instance.collection('orders').document();
ref.setData({
'date': event.date,
'totalIncome': currentState.totalForDay,
'tenPercentOfDay': currentState.totalForDay * 0.1,
'orders': listOfOrders,
});
}
} catch (e) {
print("Error uploading, $e");
print("Error uploading to Firestore");
yield SummaryError();
}
}
Is there a way for this bloc to return a "whenComplete()" method in order to display a progress indicator of some kind?