Skip to content

Instantly share code, notes, and snippets.

@chaudharydeepanshu
Created January 29, 2022 12:00
Show Gist options
  • Save chaudharydeepanshu/9de2632cd625c1a0cf7e7af1ae0f133a to your computer and use it in GitHub Desktop.
Save chaudharydeepanshu/9de2632cd625c1a0cf7e7af1ae0f133a to your computer and use it in GitHub Desktop.
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
// Platform messages are asynchronous, so we initialize in an async method.
Future<ConnectivityResult?> initConnectivity(
{required Connectivity connectivity}) async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
return await connectivity.checkConnectivity();
} on PlatformException catch (e) {
debugPrint(e.toString());
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment