Skip to content

Commit

Permalink
Merge null-safety plugins (flutter#3324)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia authored and amantoux committed Feb 8, 2021
1 parent 6a8fbc6 commit d676ab1
Show file tree
Hide file tree
Showing 113 changed files with 1,174 additions and 681 deletions.
8 changes: 8 additions & 0 deletions packages/connectivity/connectivity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 3.0.0-nullsafety.1

* Bump Dart SDK to support null safety.

## 3.0.0-nullsafety

* Migrate to null safety.

## 2.0.3

* Update Flutter SDK constraint.
Expand Down
4 changes: 4 additions & 0 deletions packages/connectivity/connectivity/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: ../../../analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
6 changes: 3 additions & 3 deletions packages/connectivity/connectivity/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

Expand All @@ -51,7 +51,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
String _connectionStatus = 'Unknown';
final Connectivity _connectivity = Connectivity();
StreamSubscription<ConnectivityResult> _connectivitySubscription;
late StreamSubscription<ConnectivityResult> _connectivitySubscription;

@override
void initState() {
Expand All @@ -69,7 +69,7 @@ class _MyHomePageState extends State<MyHomePage> {

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initConnectivity() async {
ConnectivityResult result;
ConnectivityResult result = ConnectivityResult.none;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await _connectivity.checkConnectivity();
Expand Down
3 changes: 2 additions & 1 deletion packages/connectivity/connectivity/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ dependencies:
dev_dependencies:
flutter_driver:
sdk: flutter
test: ^1.10.0-nullsafety.1
integration_test:
path: ../../../integration_test
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety.1

flutter:
uses-material-design: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(cyanglaz): Remove once https://github.com/flutter/plugins/pull/3158 is landed.
// @dart = 2.9

import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:connectivity/connectivity.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(cyanglaz): Remove once https://github.com/flutter/plugins/pull/3158 is landed.
// @dart = 2.9

import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:connectivity/connectivity.dart';
Expand Down
4 changes: 2 additions & 2 deletions packages/connectivity/connectivity/lib/connectivity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class Connectivity {
if (_singleton == null) {
_singleton = Connectivity._();
}
return _singleton;
return _singleton!;
}

Connectivity._();

static Connectivity _singleton;
static Connectivity? _singleton;

static ConnectivityPlatform get _platform => ConnectivityPlatform.instance;

Expand Down
17 changes: 10 additions & 7 deletions packages/connectivity/connectivity/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: connectivity
description: Flutter plugin for discovering the state of the network (WiFi &
mobile/cellular) connectivity on Android and iOS.
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity
version: 2.0.3
version: 3.0.0-nullsafety.1

flutter:
plugin:
Expand All @@ -21,21 +21,24 @@ dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
connectivity_platform_interface: ^1.0.2
connectivity_macos: ^0.1.0
connectivity_for_web: ^0.3.0
connectivity_platform_interface: ^2.0.0-nullsafety.1
#TODO(cyanglaz): re-endorse the below plugins when they have migrated to nnbd.
# https://github.com/flutter/flutter/issues/68669
connectivity_macos: ^0.2.0-nullsafety
# connectivity_for_web: ^0.3.0

dev_dependencies:
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
test: ^1.10.0-nullsafety.1
integration_test:
path: ../../integration_test
mockito: ^4.1.1
plugin_platform_interface: ^1.0.0
pedantic: ^1.8.0
plugin_platform_interface: ^1.1.0-nullsafety.1
pedantic: ^1.10.0-nullsafety.1

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

// TODO(cyanglaz): Remove once Mockito is migrated to null safety.
// @dart = 2.9
import 'package:connectivity/connectivity.dart';
import 'package:connectivity_platform_interface/connectivity_platform_interface.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
4 changes: 4 additions & 0 deletions packages/connectivity/connectivity_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.0-nullsafety

* Update Dart SDK constraint.

## 0.1.0+8

* Update Flutter SDK constraint.
Expand Down
4 changes: 2 additions & 2 deletions packages/connectivity/connectivity_macos/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: macOS implementation of the connectivity plugin.
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.1.0+8
version: 0.2.0-nullsafety
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity_macos

flutter:
Expand All @@ -13,7 +13,7 @@ flutter:
pluginClass: ConnectivityPlugin

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.10.0"

dependencies:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.0.0-nullsafety.1

* Bump Dart SDK to support null safety.

## 2.0.0-nullsafety

* Migrate to null safety.

## 1.0.7

* Update Flutter SDK constraint.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: ../../../analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ abstract class ConnectivityPlatform extends PlatformInterface {
}

/// Obtains the wifi name (SSID) of the connected network
Future<String> getWifiName() {
Future<String?> getWifiName() {
throw UnimplementedError('getWifiName() has not been implemented.');
}

/// Obtains the wifi BSSID of the connected network.
Future<String> getWifiBSSID() {
Future<String?> getWifiBSSID() {
throw UnimplementedError('getWifiBSSID() has not been implemented.');
}

/// Obtains the IP address of the connected wifi network
Future<String> getWifiIP() {
Future<String?> getWifiIP() {
throw UnimplementedError('getWifiIP() has not been implemented.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ class MethodChannelConnectivity extends ConnectivityPlatform {
EventChannel eventChannel =
EventChannel('plugins.flutter.io/connectivity_status');

Stream<ConnectivityResult> _onConnectivityChanged;
Stream<ConnectivityResult>? _onConnectivityChanged;

/// Fires whenever the connectivity state changes.
Stream<ConnectivityResult> get onConnectivityChanged {
if (_onConnectivityChanged == null) {
_onConnectivityChanged = eventChannel
.receiveBroadcastStream()
.map((dynamic result) => result.toString())
.map(parseConnectivityResult);
_onConnectivityChanged =
eventChannel.receiveBroadcastStream().map((dynamic result) {
return result != null ? result.toString() : '';
}).map(parseConnectivityResult);
}
return _onConnectivityChanged;
return _onConnectivityChanged!;
}

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

@override
Future<String> getWifiName() async {
String wifiName = await methodChannel.invokeMethod<String>('wifiName');
Future<String?> getWifiName() async {
String? wifiName = await methodChannel.invokeMethod<String>('wifiName');
// as Android might return <unknown ssid>, uniforming result
// our iOS implementation will return null
if (wifiName == '<unknown ssid>') {
Expand All @@ -54,29 +54,31 @@ class MethodChannelConnectivity extends ConnectivityPlatform {
}

@override
Future<String> getWifiBSSID() {
Future<String?> getWifiBSSID() {
return methodChannel.invokeMethod<String>('wifiBSSID');
}

@override
Future<String> getWifiIP() {
Future<String?> getWifiIP() {
return methodChannel.invokeMethod<String>('wifiIPAddress');
}

@override
Future<LocationAuthorizationStatus> requestLocationServiceAuthorization({
bool requestAlwaysLocationUsage = false,
}) {
return methodChannel.invokeMethod<String>(
'requestLocationServiceAuthorization', <bool>[
requestAlwaysLocationUsage
]).then(parseLocationAuthorizationStatus);
}) async {
final String requestLocationServiceResult = await methodChannel
.invokeMethod<String>('requestLocationServiceAuthorization',
<bool>[requestAlwaysLocationUsage]) ??
'';
return parseLocationAuthorizationStatus(requestLocationServiceResult);
}

@override
Future<LocationAuthorizationStatus> getLocationServiceAuthorization() {
return methodChannel
.invokeMethod<String>('getLocationServiceAuthorization')
.then(parseLocationAuthorizationStatus);
Future<LocationAuthorizationStatus> getLocationServiceAuthorization() async {
final String getLocationServiceResult = await methodChannel
.invokeMethod<String>('getLocationServiceAuthorization') ??
'';
return parseLocationAuthorizationStatus(getLocationServiceResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ description: A common platform interface for the connectivity plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.0.7
version: 2.0.0-nullsafety.1

dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
plugin_platform_interface: ^1.0.1
meta: ^1.3.0-nullsafety.3
plugin_platform_interface: ^1.1.0-nullsafety.1

dev_dependencies:
flutter_test:
sdk: flutter
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety.1

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {

group('$MethodChannelConnectivity', () {
final List<MethodCall> log = <MethodCall>[];
MethodChannelConnectivity methodChannelConnectivity;
late MethodChannelConnectivity methodChannelConnectivity;

setUp(() async {
methodChannelConnectivity = MethodChannelConnectivity();
Expand Down Expand Up @@ -42,7 +42,7 @@ void main() {
.setMockMethodCallHandler((MethodCall methodCall) async {
switch (methodCall.method) {
case 'listen':
await ServicesBinding.instance.defaultBinaryMessenger
await ServicesBinding.instance!.defaultBinaryMessenger
.handlePlatformMessage(
methodChannelConnectivity.eventChannel.name,
methodChannelConnectivity.eventChannel.codec
Expand All @@ -64,7 +64,7 @@ void main() {
});

test('getWifiName', () async {
final String result = await methodChannelConnectivity.getWifiName();
final String? result = await methodChannelConnectivity.getWifiName();
expect(result, '1337wifi');
expect(
log,
Expand All @@ -78,7 +78,7 @@ void main() {
});

test('getWifiBSSID', () async {
final String result = await methodChannelConnectivity.getWifiBSSID();
final String? result = await methodChannelConnectivity.getWifiBSSID();
expect(result, 'c0:ff:33:c0:d3:55');
expect(
log,
Expand All @@ -92,7 +92,7 @@ void main() {
});

test('getWifiIP', () async {
final String result = await methodChannelConnectivity.getWifiIP();
final String? result = await methodChannelConnectivity.getWifiIP();
expect(result, '127.0.0.1');
expect(
log,
Expand Down
8 changes: 8 additions & 0 deletions packages/device_info/device_info/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.0.0-nullsafety.1

* Bump Dart SDK to support null safety.

## 2.0.0-nullsafety

* Migrate to null safety.

## 1.0.1

* Update Flutter SDK constraint.
Expand Down
4 changes: 4 additions & 0 deletions packages/device_info/device_info/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: ../../../analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// TODO(cyanglaz): Remove once https://github.com/flutter/plugins/pull/3158 is landed.
// @dart = 2.9

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:device_info/device_info.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/device_info/device_info/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class _MyAppState extends State<MyApp> {
}

Future<void> initPlatformState() async {
Map<String, dynamic> deviceData;
Map<String, dynamic> deviceData = <String, dynamic>{};

try {
if (Platform.isAndroid) {
Expand Down

0 comments on commit d676ab1

Please sign in to comment.