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

How to have custom page load instead of "Web Page not available" in case of no internet connection #348

Closed
amankataria opened this issue Mar 12, 2019 · 4 comments

Comments

@amankataria
Copy link

I want the application to look as authentic as possible. So I want a custom page or just my website loaded (offline version, like its in google chrome mobile)

@cTatu
Copy link

cTatu commented Mar 16, 2019

You could use this package to check if there is an available connection and if it's not you could lauch the webview with a static page.

@amankataria
Copy link
Author

amankataria commented Mar 21, 2019

@cTatu

I am trying to launch a custom static html page instead of my URL(my website 'wwww.duevents.in') if there is no internet connection, since the "Web Page not available" page doesn't look very professional.

I am using this to check the internet on the device and it is working fine ('connectionStatus ==true' when the internet is connected and vice versa):

Future check() async {
try {
  final result = await InternetAddress.lookup('google.com');
  if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
    connectionStatus = true;
    print("connected $connectionStatus");
  }
} on SocketException catch (_) {
  connectionStatus = false;
  print("not connected $connectionStatus");
}
}

This is the code where I have alternate URLs to load if there is no internet connection:

WebviewScaffold(      
  url: connectionStatus == true ?"http://www.duevents.in" : Uri.dataFromString('<html><body>hello world</body></html>', mimeType: 'text/html').toString())

Somehow it always shows me the HTML Page with this code no matter if the device has an internet connection or not. Please tell me what is wrong here.

Link to issue first reported:
https://stackoverflow.com/questions/55283231/flutter-how-to-launch-static-html-page-instead-of-url-if-there-is-no-internet

Please help me with this, I'll be grateful.

@cTatu
Copy link

cTatu commented Mar 22, 2019

The only thing that I could think of is that the check() method is running asynchronous so the changes in the connectionStatus variable are made after the WebviewScaffold checking for the url.

@amankataria
Copy link
Author

@cTatu Thanks a lot for your help. This would not have been possible without you. Btw, the issue of only the html page loading was solved using a FutureBuilder.
Here is the link to solution: https://stackoverflow.com/questions/55283231/flutter-how-to-launch-static-html-page-instead-of-url-if-there-is-no-internet

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

2 participants