我已经开始在颤振中进行开发。在一种情况下,我必须检查用户是否已连接到互联网。我结合使用连接 0.4.9+5和data_connection_checker 0.3.4来检查用户是否有活动连接。
我创建了一个文件 internet_connectivity_service.dart 来执行与之相关的所有任务。
class InternetConnectivityService {
StreamSubscription<ConnectivityResult> _subscription;
/*
* This function check if the device has internet connectivity.
* With the help of DataConnectionChecker it checks for actual internet connectivity.
*/
Future<bool> _checkConnectivity() async {
if (await DataConnectionChecker().hasConnection) {
return true;
} else {
return false;
}
}
/*
* This function is invoked to on each connection change request.
* Using Connectivity package it will check for connectivity and connection type. …Run Code Online (Sandbox Code Playgroud)