(Flutter) How to launch static html page instead of URL if there is no internet connection?
The solution provided by @Mazin Ibrahim in the comments above worked for me.
So I am posting the solution here:
FutureBuilder( future: check(), // a previously-obtained Future or null builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) { if (connectionStatus == true) { //if Internet is connected return SafeArea( child: WebviewScaffold( url: "http://www.duevents.in"))} else{ //If internet is not connected return SafeArea( child: WebviewScaffold( url: Uri.dataFromString('<html><body>hello world</body></html>', mimeType: 'text/html').toString()) }})
I would suggest you to change the check()
method to return the URL directly.
Future<String> getURL() async { try { final result = await InternetAddress.lookup('google.com'); if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) { return "http://www.duevents.in"; } } on SocketException catch (_) { return Uri.dataFromString('<html><body>hello world</body></html>', mimeType: 'text/html').toString(); }}
So then in the FutureBuilder
you could use the URL returned straight away.
FutureBuilder( future: getURL(), // a previously-obtained Future or null builder: (BuildContext context, String url) { return SafeArea( child: WebviewScaffold( url: url))} })