Skip to content

Commit

Permalink
feat(connectivity)!: support multiple ConnectivityResult values at th…
Browse files Browse the repository at this point in the history
…e same time

BREAKING CHANGES: checkConnectivity and onConnectivityChanged returns list of connectivityResult. Users will need to update their apps to handle the new list of ConnectivityResult types returned by checkConnectivity and onConnectivityChanged methods.
  • Loading branch information
suquant committed Feb 21, 2024
2 parents ef1c72f + baa336f commit bc05022
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:8.2.0'
classpath 'com.android.tools.build:gradle:8.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.fluttercommunity.plus.connectivity">
<!-- <uses-permission android:name="android.permission.INTERNET" />-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.os.Handler;
import android.os.Looper;
import io.flutter.plugin.common.EventChannel;
import java.util.Collections;

/**
* The ConnectivityBroadcastReceiver receives the connectivity updates and send them to the UIThread
Expand Down Expand Up @@ -88,7 +89,7 @@ private void sendEvent() {
}

private void sendEvent(final String networkType) {
Runnable runnable = () -> events.success(networkType);
Runnable runnable = () -> events.success(Collections.singletonList(networkType));
mainHandler.post(runnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,37 @@ void main() {
expect(result, isNotNull);
});

testWidgets('connectivity on Android newer than 5 (API 21) should be wifi',
testWidgets(
'connectivity on Android newer than 5 (API 21) should contain wifi',
(WidgetTester tester) async {
final result = await connectivity.checkConnectivity();

expect(result, [ConnectivityResult.wifi]);
expect(result, contains(ConnectivityResult.wifi));
},
skip: !Platform.isAndroid ||
Platform.operatingSystemVersion.contains('5.0.2'));

testWidgets('connectivity on Android 5 (API 21) should be mobile',
testWidgets('connectivity on Android 5 (API 21) should contain mobile',
(WidgetTester tester) async {
final result = await connectivity.checkConnectivity();

expect(result, [ConnectivityResult.mobile]);
expect(result, contains(ConnectivityResult.mobile));
},
skip: !Platform.isAndroid ||
!Platform.operatingSystemVersion.contains('5.0.2'));

testWidgets('connectivity on MacOS should be ethernet',
testWidgets('connectivity on MacOS should contain ethernet',
(WidgetTester tester) async {
final result = await connectivity.checkConnectivity();

expect(result, [ConnectivityResult.ethernet]);
expect(result, contains(ConnectivityResult.ethernet));
}, skip: !Platform.isMacOS);

testWidgets('connectivity on Linux should be none',
testWidgets('connectivity on Linux should contain other',
(WidgetTester tester) async {
final result = await connectivity.checkConnectivity();

expect(result, [ConnectivityResult.other]);
expect(result, contains(ConnectivityResult.other));
}, skip: !Platform.isLinux);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_
import 'package:flutter_test/flutter_test.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart' as cTest;

Check notice on line 10 in packages/connectivity_plus/connectivity_plus/test/connectivity_test.dart

View workflow job for this annotation

GitHub Actions / Flutter Analyze

The prefix 'cTest' isn't a lower_case_with_underscores identifier.

Try changing the prefix to follow the lower_case_with_underscores style. See https://dart.dev/lints/library_prefixes to learn more about this problem.

const List<ConnectivityResult> kCheckConnectivityResult = [
ConnectivityResult.wifi
Expand All @@ -24,7 +25,7 @@ void main() {

test('checkConnectivity', () async {
final result = await connectivity.checkConnectivity();
expect(result, kCheckConnectivityResult);
expect(result, cTest.containsAll(kCheckConnectivityResult));
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
switch (methodCall.method) {
case 'check':
// Simulate returning a comma-separated string of connectivity statuses
return 'wifi,mobile';
return List<String>.from(['wifi', 'mobile']);
default:
return null;
}
Expand All @@ -45,7 +45,8 @@ void main() {
.handlePlatformMessage(
methodChannelConnectivity.eventChannel.name,
methodChannelConnectivity.eventChannel.codec
.encodeSuccessEnvelope('wifi,mobile'),
.encodeSuccessEnvelope(
List<String>.from(['wifi', 'mobile'])),
(_) {},
);
break;
Expand Down
4 changes: 2 additions & 2 deletions packages/package_info_plus/package_info_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies:
meta: ^1.8.0
path: ^1.8.2
package_info_plus_platform_interface: ^2.0.1
web: '>=0.3.0 <0.5.0'
web: ">=0.3.0 <0.6.0"

# win32 is compatible across v4 and v5 for Win32 only (not COM)
win32: ">=4.0.0 <6.0.0"
Expand All @@ -46,4 +46,4 @@ dev_dependencies:

environment:
sdk: ^3.2.0
flutter: '>=3.6.0'
flutter: ">=3.6.0"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath 'com.android.tools.build:gradle:8.2.2'
}
}

Expand Down

0 comments on commit bc05022

Please sign in to comment.