Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on iOS (Android runs perfectly) #29

Closed
jockebq opened this issue Feb 4, 2020 · 4 comments
Closed

Not working on iOS (Android runs perfectly) #29

jockebq opened this issue Feb 4, 2020 · 4 comments

Comments

@jockebq
Copy link

jockebq commented Feb 4, 2020

I have the following code, which runs perfectly on Android. But on iOS it does not seem to react to the online/offline as on Android.
I have redacted the URL's in the code:

class HomePage extends StatefulWidget {
  _State createState() => _State();
}

class _State extends State<HomePage> {
  FlutterWebviewPlugin fwp;
  final String initialUrl = 'https://example.com/link/';

  @override
  void initState() {
    super.initState();
    fwp = FlutterWebviewPlugin();
    fwp.onStateChanged.listen(onStateChange);
  }

  @override
  void dispose() {
    fwp.dispose();
    super.dispose();
  }

  void onStateChange(WebViewStateChanged state) {
    List<String> doNotSave = <String>[
      initialUrl,
    ];
    var uri = Uri.parse(state.url);
    if (state.type == WebViewState.finishLoad && !doNotSave.contains(state.url) && (uri.queryParameters["link"] == "true")) {
      storage.setString('url', state.url);
      print("Saved!");
    }
  }

  Widget build(BuildContext context) {
    // Uncomment to reset URL
    // storage.setString('url', '');
    String savedUrl = storage.getString('url') ?? '';
    String urlToLoad = savedUrl != '' ? savedUrl : initialUrl;


    return new Scaffold(
      body: OfflineBuilder(
        connectivityBuilder: (
            BuildContext context,
            ConnectivityResult connectivity,
            Widget child,
            ) {

          final bool connected = connectivity != ConnectivityResult.none;

          if (connected == true) { // Show link-page or URL from database
            fwp.reloadUrl(urlToLoad);
          }
          else { // Offline 404
            fwp.reloadUrl(Uri.dataFromString('<html><body>404</body></html>', mimeType: 'text/html').toString());
          }
          // Loading dots
          return WebviewScaffold(
            url: Uri.dataFromString('<html><body>Loading...</body></html>', mimeType: 'text/html').toString(),
            withJavascript: true,
            useWideViewPort: false,
            withZoom: false,
            scrollBar: false
          );

        },
        child: Column(
        ),
      ),
    );

  }
}

As you probably can see the app is launched with the Loading... being shown, and if it is online it should show the urlToLoad and if it is online it shows a page with 404. And it should react if the connection status changes at any time.
Why isn't this working on iOS?
It only shows me the Loading... part, but nothing else.

@jockebq
Copy link
Author

jockebq commented Feb 17, 2020

@jogboms do you have any idea why this is happening on iOS only?

@vikrant1997
Copy link

Facing the same issue....

@jogboms
Copy link
Owner

jogboms commented Jun 2, 2020

Currently tracking flutter/flutter#20980

@jogboms
Copy link
Owner

jogboms commented Jun 2, 2020

Closing in favour of #18

@jogboms jogboms closed this as completed Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants