Loader in Web View using Flutter

71 views
Skip to first unread message

Rasmi Priya

unread,
Feb 11, 2021, 6:11:28 AM2/11/21
to Flutter Development (flutter-dev)

Hi,
I create loader in webView app using Fllutter.
But some time loader lags... like after loading pages it continuous shows loader
<CODE Mention Below>
any suggestion to resolve this
or any modification
or other method
Kindly revert with the code.
Thanks


class MyApp extends StatefulWidget {
 // This widget is the root of your application.
 @override
 WebViewExampleState createState() => WebViewExampleState();
}
class WebViewExampleState extends State<MyApp> {
 num position = 1 ;
 final key = UniqueKey();
 @override
 void initState() {
   super.initState();
   // Enable hybrid composition.
   if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
 }
 @override
 Widget build(BuildContext context) {
   return SafeArea(
       child: Scaffold(
           body: IndexedStack(
               index: position,
               children: <Widget>[

                 WebView(
                   initialUrl: 'https://www.youtube.com/',
                   javascriptMode: JavascriptMode.unrestricted,
                   key: key ,
                   onPageFinished: doneLoading,
                   onPageStarted: startLoading,
                 ),

                 Container(
                   color: Colors.white,
                   child: Center(
                       child: CircularProgressIndicator()),
                 ),

               ])
       ),
   );
 }
 doneLoading(String A) {
   setState(() {
     position = 0;
   });
 }
 startLoading(String A){
   setState(() {
     position = 1;
   });
 }

}
Reply all
Reply to author
Forward
0 new messages