Search code examples
androidflutterwebviewrefreshreload

Instance member 'reload' can't be accessed using static access


I'm working on aflutter project and i'm trying to reload my webview using this but they give me this error : Instance member 'reload' can't be accessed using static access this is my code

bool connectionStatus = true;
Future check() async {
  Timer.periodic(new Duration(seconds: 10), (time) async {
    if (connectionStatus == false) WebViewController.reload();
    try {
      final result = await InternetAddress.lookup('google.com');
      if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
        connectionStatus = true;
      }
    } on SocketException catch (_) {
      connectionStatus = false;
    } });
}

Solution

  • You need to call the reload() method for you instance of the WebViewController since it is not a static method.

    So you must have created an instance of WebViewController somewhere. You need to save a reference, like

    final _controller = WebViewController();
    

    Then, in your check() method, use

    _controller.reload();