I tried
setState(() {isLoading = true})
//do something
setState(() {isLoading = false})
in the onTab(){}
but with setState the data like pdfFile and pdfController gets overridden and the app is not pushing to a new route.
Well, my question is: How to show a loading animation to user and if the loading stuff is finished, push to the screen with the downloaded data? Maybe I need something without setState? What possibilities we have?
body: StreamBuilder(
stream: firebase.base
.collection('xxx')
.doc(firebase.auth.currentUser!.uid)
.collection("xxx")
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
final liste = snapshot.data!.docs;
return Column(
children: [
Container(
height: 400,
child: ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: liste.length,
itemBuilder: (BuildContext context, int index) {
Map data = snapshot.data!.docs[index].data() as Map;
String fileName = data['fileName'];
String url = data['url'];
return GestureDetector(
onTap: () async {
http.Response pdfFile =
await http.get(Uri.parse(url));
final pdfController = PdfController(
document:
PdfDocument.openData(pdfFile.bodyBytes));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
PdfViewScreen(pdfController, fileName)));
},
CodePudding user response:
You can use else
expression after curly bracket. Or use only return Center(child: CircularProgressIndicator());
after if
CodePudding user response:
Perhaps the follow logic works for you:
onTap
only redirects the user to PdfViewScreen. In PdfViewScreen you use a FutureBuilder to resolve http.get(Uri.parse(url))
after which the FutureBuilder will return the PDFviewer that you use. In the FutureBuilder you can then show a progressIndicator