Skip to content

Commit

Permalink
utils
Browse files Browse the repository at this point in the history
  • Loading branch information
engineer-ece committed Feb 12, 2024
1 parent d7166b9 commit 034b18f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,24 @@ abstract class ConnectivityPlatform extends PlatformInterface {
throw UnimplementedError('checkConnectivity() has not been implemented.');
}



/// Returns a Stream of ConnectivityResults changes.
Stream<ConnectivityResult> get onConnectivityChanged {
throw UnimplementedError(
'get onConnectivityChanged has not been implemented.');
}


Future<int> wifiStrength() {
throw UnimplementedError('wifiStrength() has not been implemented.');
}

Stream<int> get onWifiStrengthChanged {
throw UnimplementedError(
'get onConnectivityChanged has not been implemented.');
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:ffi';

Check warning on line 6 in packages/connectivity_plus/connectivity_plus_platform_interface/lib/method_channel_connectivity.dart

View workflow job for this annotation

GitHub Actions / Flutter Analyze

Unused import: 'dart:ffi'.

Try removing the import directive. See https://dart.dev/diagnostics/unused_import to learn more about this problem.

import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart';
import 'package:flutter/services.dart';
Expand All @@ -23,6 +24,8 @@ class MethodChannelConnectivity extends ConnectivityPlatform {
const EventChannel('dev.fluttercommunity.plus/connectivity_status');

Stream<ConnectivityResult>? _onConnectivityChanged;
Stream<int>? _onWifiStrengthChanged;


/// Fires whenever the connectivity state changes.
@override
Expand All @@ -34,10 +37,31 @@ class MethodChannelConnectivity extends ConnectivityPlatform {
return _onConnectivityChanged!;
}

@override
Stream<int> get onWifiStrengthChanged {
_onWifiStrengthChanged ??= eventChannel
.receiveBroadcastStream()
.map((dynamic result) => result as int)
.map(strengthResult);
return _onWifiStrengthChanged!;
}

@override
Future<ConnectivityResult> checkConnectivity() {
return methodChannel
.invokeMethod<String>('check')
.then((value) => parseConnectivityResult(value ?? ''));
}


@override
Future<int> wifiStrength() {
return methodChannel
.invokeMethod<int>('wifi_strength')
.then((value) => strengthResult(value!));

}



}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ ConnectivityResult parseConnectivityResult(String state) {
return ConnectivityResult.none;
}
}

int strengthResult(int value) {
return value;
}

0 comments on commit 034b18f

Please sign in to comment.