Migrate all of examples/layers to sound null safety (#68744)

This commit is contained in:
Michael Goderbauer
2020-10-22 13:33:07 -07:00
committed by GitHub
parent 8273b99294
commit dd2ea7c503
17 changed files with 54 additions and 65 deletions

View File

@@ -5,7 +5,6 @@
import 'dart:convert';
import 'dart:isolate';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -17,7 +16,7 @@ typedef OnResultListener = void Function(String result);
// The choice of JSON parsing here is meant as an example that might surface
// in real-world applications.
class Calculator {
Calculator({ @required this.onProgressListener, @required this.onResultListener, String data })
Calculator({ required this.onProgressListener, required this.onResultListener, String? data })
: assert(onProgressListener != null),
assert(onResultListener != null),
// In order to keep the example files smaller, we "cheat" a little and
@@ -53,7 +52,7 @@ class Calculator {
}
}
static String _replicateJson(String data, int count) {
static String _replicateJson(String? data, int count) {
final StringBuffer buffer = StringBuffer()..write('[');
for (int i = 0; i < count; i++) {
buffer.write(data);
@@ -85,7 +84,7 @@ class CalculationMessage {
// This class manages these ports and maintains state related to the
// progress of the background computation.
class CalculationManager {
CalculationManager({ @required this.onProgressListener, @required this.onResultListener })
CalculationManager({ required this.onProgressListener, required this.onResultListener })
: assert(onProgressListener != null),
assert(onResultListener != null),
_receivePort = ReceivePort() {
@@ -120,7 +119,7 @@ class CalculationManager {
if (isRunning) {
_state = CalculationState.idle;
if (_isolate != null) {
_isolate.kill(priority: Isolate.immediate);
_isolate!.kill(priority: Isolate.immediate);
_isolate = null;
_completed = 0.0;
_total = 1.0;
@@ -129,7 +128,7 @@ class CalculationManager {
}
final ReceivePort _receivePort;
Isolate _isolate;
Isolate? _isolate;
void _runCalculation() {
// Load the JSON string. This is done in the main isolate because spawned
@@ -209,8 +208,8 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
String _label = 'Start';
String _result = ' ';
double _progress = 0.0;
AnimationController _animation;
CalculationManager _calculationManager;
late AnimationController _animation;
late CalculationManager _calculationManager;
@override
void initState() {

View File

@@ -5,7 +5,7 @@
import 'package:flutter/widgets.dart';
class LifecycleWatcher extends StatefulWidget {
const LifecycleWatcher({ Key key }) : super(key: key);
const LifecycleWatcher({ Key? key }) : super(key: key);
@override
_LifecycleWatcherState createState() => _LifecycleWatcherState();
@@ -13,17 +13,17 @@ class LifecycleWatcher extends StatefulWidget {
class _LifecycleWatcherState extends State<LifecycleWatcher>
with WidgetsBindingObserver {
AppLifecycleState _lastLifecycleState;
AppLifecycleState? _lastLifecycleState;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance!.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}