Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Webview change webpage is not available

I wanna change the "Webpage not available", in my WebView application, if the user doesn't have internet.

I read the documentation, and try some another puglins

import 'package:webview_flutter/webview_flutter.dart';
[...]
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: const WebView(
        initialUrl: 'https://google.com',
        javascriptMode: JavascriptMode.unrestricted,
      ),
    );
  }
}
like image 877
Juliano Braz Avatar asked Oct 20 '25 06:10

Juliano Braz


1 Answers

Just Add onWebResourceError method to your Webview.

    WebView(
        onWebResourceError: (WebResourceError webviewerrr) {
            print("Handle your Error Page here");
        },
        initialUrl: "your url"
        javascriptMode: JavascriptMode.unrestricted,
        onPageFinished: (String url) {
            print('Page finished loading:');
        },
    );
like image 174
SANDEEP SREESHAN Avatar answered Oct 22 '25 21:10

SANDEEP SREESHAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!