Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[sensors] Update to NNBD stable #3589

Merged
merged 1 commit into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/sensors/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
20 changes: 10 additions & 10 deletions packages/sensors/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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 @@ -41,21 +41,21 @@ class _MyHomePageState extends State<MyHomePage> {
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(
Expand Down
29 changes: 14 additions & 15 deletions packages/sensors/example/lib/snake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ class SnakeBoardPainter extends CustomPainter {
}

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) {
Expand Down Expand Up @@ -96,21 +95,21 @@ class SnakeState extends State<Snake> {
}

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;
Expand All @@ -119,7 +118,7 @@ class GameState {
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);

Expand Down
7 changes: 3 additions & 4 deletions packages/sensors/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ dev_dependencies:
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"
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions packages/sensors/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: sensors
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:
Expand All @@ -18,14 +18,14 @@ dependencies:
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"