I want to check if there an internet connection on my device I already try the Connectivity but it doesn't help me because it check if the device is connecting to wifi or not, but doesn't discover if there an internet problem my code :
import 'dart:async';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:flutter/services.dart';
class WebviewUi extends StatefulWidget {
@override
_WebviewState createState() => _WebviewState();
}
class _WebviewState extends State<WebviewUi> {
String _connectionStatus;
final Connectivity _connectivity = new Connectivity();
StreamSubscription<ConnectivityResult> _connectivitySubscription;
@override
void initState() {
super.initState();
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.deepOrangeAccent)
);
_connectivitySubscription =
_connectivity.onConnectivityChanged.listen((ConnectivityResult result){
setState(() {
_connectionStatus = result.toString();
print('Connection Status : $_connectionStatus');
});
});
}
@override
void dispose() {
_connectivitySubscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(0),
child: AppBar(
),
),
body: (_connectionStatus == "ConnectivityResult.mobile" ||
_connectionStatus == "ConnectivityResult.wifi") ?
WebviewScaffold(
/*appBar: AppBar(
title: Text(''),
backgroundColor: Colors.deepOrangeAccent,
),*/
url: "https://www.google.net/",
withJavascript: true,
)
:
Container(
child: Image.asset(
'assets/Internet-Access-Error.jpg',
)
)
);
}
}
when I tried this code on the emulator I switched to airplane mode on my labtop it's show:
net::ERR_NAME_NOT_RESOLVED
but I want to display an widget that tell the there's an internet problem or no internet. How can I preform this I searched a lot over the websites and facebook groups I didn't find any solution