Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to show a CircularProgressIndicator before WebView loads the page?

Tags:

I'm using the webview_fluttter plugin, but I can't find a way to show a CircularProgressIndicator before the webview shows the page...

What's the equivalent of Androids WebViewClient onPageStarted/onPageFinished?

WebView(   initialUrl: url,   onWebViewCreated: (controller) {   }, )
like image 220
rlecheta Avatar asked Feb 14 '19 19:02

rlecheta


1 Answers

In version 0.3.5 there is 'onPageFinished' callback. You can create WebView container with IndexedStack.

import 'package:flutter/material.dart';  import 'package:webview_flutter/webview_flutter.dart';    class _WebViewContainerState extends State < WebViewContainer > {    var _url;    final _key = UniqueKey();    _WebViewContainerState(this._url);    num _stackToView = 1;      void _handleLoad(String value) {      setState(() {        _stackToView = 0;      });    }      @override    Widget build(BuildContext context) {      return Scaffold(        appBar: AppBar(),        body: IndexedStack(          index: _stackToView,          children: [            Column(              children: < Widget > [                Expanded(                  child: WebView(                    key: _key,                    javascriptMode: JavascriptMode.unrestricted,                    initialUrl: _url,                    onPageFinished: _handleLoad,                  )                ),              ],            ),            Container(              color: Colors.white,              child: Center(                child: CircularProgressIndicator(),              ),            ),          ],        )      );    }  }    class WebViewContainer extends StatefulWidget {    final url;    WebViewContainer(this.url);    @override    createState() => _WebViewContainerState(this.url);  }
like image 170
Oleksandr Avatar answered Sep 28 '22 21:09

Oleksandr