[sensors] Update to NNBD stable (#3589)
Includes migrating example to null-safety.
diff --git a/packages/sensors/CHANGELOG.md b/packages/sensors/CHANGELOG.md
index 8ff904b..295c32a 100644
--- a/packages/sensors/CHANGELOG.md
+++ b/packages/sensors/CHANGELOG.md
@@ -1,8 +1,4 @@
-## 2.0.0-nullsafety
-
-* * Update version to (semi-belatedly) meet 1.0-consistency promise.
-
-## 0.5.0-nullsafety
+## 2.0.0
* Migrate to null safety.
diff --git a/packages/sensors/example/lib/main.dart b/packages/sensors/example/lib/main.dart
index 575e049..d6f0138 100644
--- a/packages/sensors/example/lib/main.dart
+++ b/packages/sensors/example/lib/main.dart
@@ -28,7 +28,7 @@
}
class MyHomePage extends StatefulWidget {
- MyHomePage({Key key, this.title}) : super(key: key);
+ MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@@ -41,21 +41,21 @@
static const int _snakeColumns = 20;
static const double _snakeCellSize = 10.0;
- List<double> _accelerometerValues;
- List<double> _userAccelerometerValues;
- List<double> _gyroscopeValues;
+ List<double>? _accelerometerValues;
+ List<double>? _userAccelerometerValues;
+ List<double>? _gyroscopeValues;
List<StreamSubscription<dynamic>> _streamSubscriptions =
<StreamSubscription<dynamic>>[];
@override
Widget build(BuildContext context) {
- final List<String> accelerometer =
- _accelerometerValues?.map((double v) => v.toStringAsFixed(1))?.toList();
- final List<String> gyroscope =
- _gyroscopeValues?.map((double v) => v.toStringAsFixed(1))?.toList();
- final List<String> userAccelerometer = _userAccelerometerValues
+ final List<String>? accelerometer =
+ _accelerometerValues?.map((double v) => v.toStringAsFixed(1)).toList();
+ final List<String>? gyroscope =
+ _gyroscopeValues?.map((double v) => v.toStringAsFixed(1)).toList();
+ final List<String>? userAccelerometer = _userAccelerometerValues
?.map((double v) => v.toStringAsFixed(1))
- ?.toList();
+ .toList();
return Scaffold(
appBar: AppBar(
diff --git a/packages/sensors/example/lib/snake.dart b/packages/sensors/example/lib/snake.dart
index d6b2f9b..72f2747 100644
--- a/packages/sensors/example/lib/snake.dart
+++ b/packages/sensors/example/lib/snake.dart
@@ -56,15 +56,14 @@
}
class SnakeState extends State<Snake> {
- SnakeState(int rows, int columns, this.cellSize) {
- state = GameState(rows, columns);
- }
+ SnakeState(int rows, int columns, this.cellSize)
+ : state = GameState(rows, columns);
double cellSize;
GameState state;
- AccelerometerEvent acceleration;
- StreamSubscription<AccelerometerEvent> _streamSubscription;
- Timer _timer;
+ AccelerometerEvent? acceleration;
+ late StreamSubscription<AccelerometerEvent> _streamSubscription;
+ late Timer _timer;
@override
Widget build(BuildContext context) {
@@ -96,21 +95,21 @@
}
void _step() {
- final math.Point<int> newDirection = acceleration == null
+ final AccelerometerEvent? currentAcceleration = acceleration;
+ final math.Point<int>? newDirection = currentAcceleration == null
? null
- : acceleration.x.abs() < 1.0 && acceleration.y.abs() < 1.0
+ : currentAcceleration.x.abs() < 1.0 && currentAcceleration.y.abs() < 1.0
? null
- : (acceleration.x.abs() < acceleration.y.abs())
- ? math.Point<int>(0, acceleration.y.sign.toInt())
- : math.Point<int>(-acceleration.x.sign.toInt(), 0);
+ : (currentAcceleration.x.abs() < currentAcceleration.y.abs())
+ ? math.Point<int>(0, currentAcceleration.y.sign.toInt())
+ : math.Point<int>(-currentAcceleration.x.sign.toInt(), 0);
state.step(newDirection);
}
}
class GameState {
- GameState(this.rows, this.columns) {
- snakeLength = math.min(rows, columns) - 5;
- }
+ GameState(this.rows, this.columns)
+ : snakeLength = math.min(rows, columns) - 5;
int rows;
int columns;
@@ -119,7 +118,7 @@
List<math.Point<int>> body = <math.Point<int>>[const math.Point<int>(0, 0)];
math.Point<int> direction = const math.Point<int>(1, 0);
- void step(math.Point<int> newDirection) {
+ void step(math.Point<int>? newDirection) {
math.Point<int> next = body.last + direction;
next = math.Point<int>(next.x % columns, next.y % rows);
diff --git a/packages/sensors/example/pubspec.yaml b/packages/sensors/example/pubspec.yaml
index d4702ac..0cd30b1 100644
--- a/packages/sensors/example/pubspec.yaml
+++ b/packages/sensors/example/pubspec.yaml
@@ -17,12 +17,11 @@
sdk: flutter
integration_test:
path: ../../integration_test
- pedantic: ^1.8.0
+ pedantic: ^1.10.0
flutter:
uses-material-design: true
environment:
- sdk: ">=2.0.0-dev.28.0 <3.0.0"
- flutter: ">=1.9.1+hotfix.2"
-
+ sdk: ">=2.12.0-259.9.beta <3.0.0"
+ flutter: ">=1.20.0"
diff --git a/packages/sensors/example/test_driver/test/integration_test.dart b/packages/sensors/example/test_driver/test/integration_test.dart
index 7a2c213..a8a56aa 100644
--- a/packages/sensors/example/test_driver/test/integration_test.dart
+++ b/packages/sensors/example/test_driver/test/integration_test.dart
@@ -2,6 +2,8 @@
// 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.
+// @dart = 2.9
+
import 'dart:async';
import 'dart:convert';
import 'dart:io';
diff --git a/packages/sensors/pubspec.yaml b/packages/sensors/pubspec.yaml
index 0416779..da45c82 100644
--- a/packages/sensors/pubspec.yaml
+++ b/packages/sensors/pubspec.yaml
@@ -2,7 +2,7 @@
description: Flutter plugin for accessing the Android and iOS accelerometer and
gyroscope sensors.
homepage: https://github.com/flutter/plugins/tree/master/packages/sensors
-version: 2.0.0-nullsafety
+version: 2.0.0
flutter:
plugin:
@@ -18,14 +18,14 @@
sdk: flutter
dev_dependencies:
- test: ^1.16.0-nullsafety
+ test: ^1.16.0
flutter_test:
sdk: flutter
integration_test:
path: ../integration_test
mockito: ^5.0.0-nullsafety.0
- pedantic: ^1.10.0-nullsafety
+ pedantic: ^1.10.0
environment:
- sdk: ">=2.12.0-0 <3.0.0"
+ sdk: ">=2.12.0-259.9.beta <3.0.0"
flutter: ">=1.12.13+hotfix.5"