Hello,
On some devices the text search can take a while, so I want to show a CircularProgressIndicator while the search is taking place.
This code gives the result I'm expecting:
But when I replace the delay with the controller searchText as in the following, the first setState doesn't appear to rebuild my stateful widget, but the second does, so the CircularProgressIndicator doesn't show at all. As far as my stateful widget is concerned, the _pdfAppBarState goes straight to PdfAppBarState.searchComplete.
Any ideas why this might be?
I thought that maybe searchText is blocking the main thread and perhaps I could run searchText in a separate Isolate, but it doesn't appear possible to isolate the searchText method due to dependencies in the main thread (I tried passing the PdfViewerController as a message to the new isolate but got an error relating to dependency on dart:ui).
Thank you Ravi
|
import 'package:flutter/material.dart'; void main() { runApp(MaterialApp(home: HomePage())); } /// Represents Homepage for Navigation class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { bool _showProgressbar = false; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Home Page'), backgroundColor: Colors.deepOrange), body: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ TextField( decoration: const InputDecoration(hintText: 'Enter text'), onSubmitted: (String str) { setState(() { _showProgressbar = true; }); setState(() { _showProgressbar = false; }); }), Visibility( visible: _showProgressbar, child: const CircularProgressIndicator()), ])); } } |
Thanks Ravi. I see what you mean. Strange that it works fine if the searchText() is replaced with:
await Future.delayed(const Duration(seconds: 5));
If I combine the Future.delayed along with searchText(), I get the state changes I expect, but the CircularProgressIndicator only spins during the Future.delayed. It freezes when searchText() is called.
I'll see if I can find a similar example that gives me an alternative way to achieve the user experience that I'm looking for.
Thanks Dilli babu, I have added my vote to this feature request.