Answers for "onload error flutter"

0

onload error flutter

InAppWebViewController webViewController;
bool showErrorPage = false;
@override
Widget build(BuildContext context) {
  return Container(
    child: Stack(
      children: <Widget>[
        InAppWebView(
          initialUrl: 'https://fail.page.asd',
          onWebViewCreated: (InAppWebViewController controller) {
            webViewController = controller;
          },
          onLoadError: (
            InAppWebViewController controller,
            String url,
            int i,
            String s
          ) async {
            print('CUSTOM_HANDLER: $i, $s');
            /** instead of printing the console message i want to render a static page or display static message **/
            showError();
          },
          onLoadHttpError: (InAppWebViewController controller, String url,
              int i, String s) async {
            print('CUSTOM_HANDLER: $i, $s');
            /** instead of printing the console message i want to render a static page or display static message **/
            showError();
          },
        ),
        showErrorPage ? Center(
          child: Container(
            color: Colors.white,
            alignment: Alignment.center,
            height: double.infinity,
            width: double.infinity,
            child: Text('Page failed to open (WIDGET)'),
          ),
        ) : SizedBox(height: 0, width: 0),
      ],
    ),
  );
}

void showError(){
  setState(() {
    showErrorPage = true;
  });
}

void hideError(){
  setState(() {
    showErrorPage = false;
  });
}
Posted by: Guest on February-15-2022

Browse Popular Code Answers by Language