File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,23 +3,14 @@ import 'package:fa_flutter_core/fa_flutter_core.dart';
33
44import '../interceptor/auth_interceptor.dart' ;
55import '../interceptor/logging_interceptor.dart' ;
6- import '../interceptor/network/network_info.dart' ;
7- import '../interceptor/network_interceptor.dart' ;
86
97const _debugBaseUrl = 'https://fa-maapins-debug.fieldassist.io/api/' ;
108
119final locator = GetIt .instance;
1210
1311class Injector {
1412 Future <void > init () async {
15- locator.registerLazySingleton <NetworkInfo >(
16- () => NetworkInfoImpl (
17- connectionChecker: InternetConnectionChecker .instance,
18- ),
19- );
20-
2113 final interceptors = [
22- MyNetworkInterceptor (networkInfo: locator ()),
2314 MyAuthInterceptor (),
2415 // ErrorInterceptor(),
2516 MyLoggingInterceptor (),
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -11,3 +11,4 @@ export 'src/api_options/api_options.dart';
1111export 'src/interceptors/cache_interceptor.dart' ;
1212export 'src/interceptors/cancel_token_interceptor.dart' ;
1313export 'src/interceptors/refresh_token_interceptor.dart' ;
14+ export 'src/utils/network_checker.dart' ;
Original file line number Diff line number Diff line change 11import 'package:dio/dio.dart' ;
2+ import 'package:fa_flutter_core/fa_flutter_core.dart' ;
23
4+ import '../../fa_flutter_api_client.dart' ;
35import '../exceptions/errors.dart' ;
46
57abstract class NetworkInterceptor extends Interceptor {
@@ -8,7 +10,7 @@ abstract class NetworkInterceptor extends Interceptor {
810 RequestOptions options,
911 RequestInterceptorHandler handler,
1012 ) async {
11- final isConnected = await isInternetConnected () ;
13+ final isConnected = await NetworkConnectivityService .instance.isConnected ;
1214 if (! isConnected) {
1315 // Intentional delay to mimic making server request behavior
1416 await Future .delayed (getDelay ());
@@ -27,6 +29,4 @@ abstract class NetworkInterceptor extends Interceptor {
2729 Duration getDelay () {
2830 return Duration (milliseconds: 500 );
2931 }
30-
31- Future <bool > isInternetConnected ();
3232}
Original file line number Diff line number Diff line change 1+ import 'package:internet_connection_checker/internet_connection_checker.dart' ;
2+
3+ class NetworkConnectivityService {
4+ NetworkConnectivityService ._internal ()
5+ : connectionChecker = InternetConnectionChecker .createInstance (
6+ addresses: [
7+ AddressCheckOption (uri: Uri .parse ('https://www.google.com' )),
8+ AddressCheckOption (uri: Uri .parse ('https://www.bing.com' )),
9+ AddressCheckOption (uri: Uri .parse ('https://www.amazon.com' )),
10+ AddressCheckOption (uri: Uri .parse ('https://www.cloudflare.com' )),
11+ ],
12+ );
13+
14+ static NetworkConnectivityService ? _instance;
15+
16+ static NetworkConnectivityService get instance {
17+ _instance ?? = NetworkConnectivityService ._internal ();
18+ return _instance! ;
19+ }
20+
21+ final InternetConnectionChecker connectionChecker;
22+
23+ Future <bool > get isConnected => connectionChecker.hasConnection;
24+ }
You can’t perform that action at this time.
0 commit comments