Skip to content

Commit

Permalink
refactor: add ConnectivityService to handle network connections
Browse files Browse the repository at this point in the history
  • Loading branch information
mediocre9 committed Jan 6, 2024
1 parent 2813006 commit cad9d70
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/services/connectivity_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:connectivity_plus/connectivity_plus.dart';

class NetworkException implements Exception {
String message;

NetworkException({this.message = "Network state is offline!"});

@override
String toString() => message;
}

abstract interface class IConnectivityService {
Future<bool> isOffline();
}

class ConnectivityService implements IConnectivityService {
final Connectivity connectivity = Connectivity();

ConnectivityService();

@override
Future<bool> isOffline() async {
ConnectivityResult result = await connectivity.checkConnectivity();
return result == ConnectivityResult.none;
}
}

0 comments on commit cad9d70

Please sign in to comment.