Unverified Commit dd2ea7c5 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

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

parent 8273b992
......@@ -604,7 +604,7 @@ Future<void> _runFrameworkTests() async {
await _runFlutterTest(path.join(flutterRoot, 'dev', 'manual_tests'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'vitool'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'examples', 'hello_world'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'), tableData: bigqueryApi?.tabledata, options: mixedModeNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'), tableData: bigqueryApi?.tabledata, options: soundNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'benchmarks', 'test_apps', 'stocks'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'), tableData: bigqueryApi?.tabledata, tests: <String>[path.join('test', 'src', 'real_tests')]);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_goldens'), tableData: bigqueryApi?.tabledata);
......
......@@ -2,7 +2,7 @@ name: flutter_examples_layers
environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.10.0-0.0.dev <3.0.0"
dependencies:
flutter:
......
......@@ -9,7 +9,7 @@ import 'dart:typed_data';
import 'dart:ui' as ui;
// A paragraph represents a rectangular region that contains some text.
ui.Paragraph paragraph;
late ui.Paragraph paragraph;
ui.Picture paint(ui.Rect paintBounds) {
final ui.PictureRecorder recorder = ui.PictureRecorder();
......
......@@ -8,7 +8,7 @@
import 'dart:typed_data';
import 'dart:ui' as ui;
ui.Color color;
late ui.Color color;
ui.Picture paint(ui.Rect paintBounds) {
// First we create a PictureRecorder to record the commands we're going to
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.10
// This example shows how to build a render tree with a non-cartesian coordinate
// system. Most of the guts of this examples are in src/sector_layout.dart.
......
......@@ -48,7 +48,7 @@ void main() {
subrow.add(RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0)));
row.add(subrow);
table.add(row);
final FlexParentData rowParentData = row.parentData as FlexParentData;
final FlexParentData rowParentData = row.parentData! as FlexParentData;
rowParentData.flex = 1;
}
......@@ -71,7 +71,7 @@ void main() {
row.add(RenderSolidColorBox(const Color(0xFFCCCCFF), desiredSize: const Size(160.0, 60.0)));
row.mainAxisAlignment = justify;
table.add(row);
final FlexParentData rowParentData = row.parentData as FlexParentData;
final FlexParentData rowParentData = row.parentData! as FlexParentData;
rowParentData.flex = 1;
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.10
import 'dart:math' as math;
import 'package:flutter/rendering.dart';
......
......@@ -20,7 +20,7 @@ List<Color> _kColors = <Color>[
/// A simple model object for a dot that reacts to pointer pressure.
class Dot {
Dot({ Color color }) : _paint = Paint()..color = color;
Dot({ required Color color }) : _paint = Paint()..color = color;
final Paint _paint;
Offset position = Offset.zero;
......@@ -65,7 +65,7 @@ class RenderDots extends RenderBox {
@override
void handleEvent(PointerEvent event, BoxHitTestEntry entry) {
if (event is PointerDownEvent) {
final Color color = _kColors[event.pointer.remainder(_kColors.length) as int];
final Color color = _kColors[event.pointer.remainder(_kColors.length)];
_dots[event.pointer] = Dot(color: color)..update(event);
// We call markNeedsPaint to indicate that our painting commands have
// changed and that paint needs to be called before displaying a new frame
......@@ -76,7 +76,7 @@ class RenderDots extends RenderBox {
_dots.remove(event.pointer);
markNeedsPaint();
} else if (event is PointerMoveEvent) {
_dots[event.pointer].update(event);
_dots[event.pointer]!.update(event);
markNeedsPaint();
}
}
......@@ -126,7 +126,7 @@ void main() {
//
// We use the StackParentData of the paragraph to position the text in the top
// left corner of the screen.
final StackParentData paragraphParentData = paragraph.parentData as StackParentData;
final StackParentData paragraphParentData = paragraph.parentData! as StackParentData;
paragraphParentData
..top = 40.0
..left = 20.0;
......
......@@ -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() {
......
......@@ -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();
}
......
......@@ -39,7 +39,7 @@ class RenderDots extends RenderConstrainedBox {
}
class Dots extends SingleChildRenderObjectWidget {
const Dots({ Key key, Widget child }) : super(key: key, child: child);
const Dots({ Key? key, Widget? child }) : super(key: key, child: child);
@override
RenderDots createRenderObject(BuildContext context) => RenderDots();
......
......@@ -6,14 +6,14 @@ import 'package:flutter/material.dart';
class _GesturePainter extends CustomPainter {
const _GesturePainter({
this.zoom,
this.offset,
this.swatch,
this.forward,
this.scaleEnabled,
this.tapEnabled,
this.doubleTapEnabled,
this.longPressEnabled,
required this.zoom,
required this.offset,
required this.swatch,
required this.forward,
required this.scaleEnabled,
required this.tapEnabled,
required this.doubleTapEnabled,
required this.longPressEnabled,
});
final double zoom;
......@@ -61,12 +61,12 @@ class GestureDemo extends StatefulWidget {
class GestureDemoState extends State<GestureDemo> {
Offset _startingFocalPoint;
late Offset _startingFocalPoint;
Offset _previousOffset;
late Offset _previousOffset;
Offset _offset = Offset.zero;
double _previousZoom;
late double _previousZoom;
double _zoom = 1.0;
static const List<MaterialColor> kSwatches = <MaterialColor>[
......@@ -175,7 +175,7 @@ class GestureDemoState extends State<GestureDemo> {
children: <Widget>[
Checkbox(
value: _scaleEnabled,
onChanged: (bool value) { setState(() { _scaleEnabled = value; }); },
onChanged: (bool? value) { setState(() { _scaleEnabled = value!; }); },
),
const Text('Scale'),
],
......@@ -184,7 +184,7 @@ class GestureDemoState extends State<GestureDemo> {
children: <Widget>[
Checkbox(
value: _tapEnabled,
onChanged: (bool value) { setState(() { _tapEnabled = value; }); },
onChanged: (bool? value) { setState(() { _tapEnabled = value!; }); },
),
const Text('Tap'),
],
......@@ -193,7 +193,7 @@ class GestureDemoState extends State<GestureDemo> {
children: <Widget>[
Checkbox(
value: _doubleTapEnabled,
onChanged: (bool value) { setState(() { _doubleTapEnabled = value; }); },
onChanged: (bool? value) { setState(() { _doubleTapEnabled = value!; }); },
),
const Text('Double Tap'),
],
......@@ -202,7 +202,7 @@ class GestureDemoState extends State<GestureDemo> {
children: <Widget>[
Checkbox(
value: _longPressEnabled,
onChanged: (bool value) { setState(() { _longPressEnabled = value; }); },
onChanged: (bool? value) { setState(() { _longPressEnabled = value!; }); },
),
const Text('Long Press'),
],
......
......@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class AdaptedListItem extends StatelessWidget {
const AdaptedListItem({ Key key, this.name }) : super(key: key);
const AdaptedListItem({ Key? key, required this.name }) : super(key: key);
final String name;
......@@ -26,7 +26,7 @@ class AdaptedListItem extends StatelessWidget {
}
class AdaptedGridItem extends StatelessWidget {
const AdaptedGridItem({ Key key, this.name }) : super(key: key);
const AdaptedGridItem({ Key? key, required this.name }) : super(key: key);
final String name;
......@@ -65,13 +65,13 @@ const double _kMaxTileWidth = 150.0;
const double _kGridViewBreakpoint = 450.0;
class AdaptiveContainer extends StatelessWidget {
const AdaptiveContainer({ Key key, this.names }) : super(key: key);
const AdaptiveContainer({ Key? key, required this.names }) : super(key: key);
final List<String> names;
@override
Widget build(BuildContext context) {
if (MediaQuery.of(context).size.width < _kGridViewBreakpoint) {
if (MediaQuery.of(context)!.size.width < _kGridViewBreakpoint) {
return ListView(
itemExtent: _kListItemExtent,
children: names.map<Widget>((String name) => AdaptedListItem(name: name)).toList(),
......
......@@ -54,9 +54,9 @@ class SectorAppState extends State<SectorApp> {
int index = 0;
while (index < actualSectorSizes.length && index < wantedSectorSizes.length && actualSectorSizes[index] == wantedSectorSizes[index])
index += 1;
final RenderSectorRing ring = sectors.child as RenderSectorRing;
final RenderSectorRing ring = sectors.child! as RenderSectorRing;
while (index < actualSectorSizes.length) {
ring.remove(ring.lastChild);
ring.remove(ring.lastChild!);
actualSectorSizes.removeLast();
}
while (index < wantedSectorSizes.length) {
......
......@@ -11,13 +11,13 @@ import '../rendering/src/solid_color_box.dart';
void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int flex = 0 }) {
final RenderSolidColorBox child = RenderSolidColorBox(backgroundColor);
parent.add(child);
final FlexParentData childParentData = child.parentData as FlexParentData;
final FlexParentData childParentData = child.parentData! as FlexParentData;
childParentData.flex = flex;
}
// Solid color, Widget version
class Rectangle extends StatelessWidget {
const Rectangle(this.color, { Key key }) : super(key: key);
const Rectangle(this.color, { Key? key }) : super(key: key);
final Color color;
......@@ -31,8 +31,8 @@ class Rectangle extends StatelessWidget {
}
}
double value;
RenderObjectToWidgetElement<RenderBox> element;
double? value;
RenderObjectToWidgetElement<RenderBox>? element;
BuildOwner owner = BuildOwner();
void attachWidgetTreeToRenderTree(RenderProxyBox container) {
element = RenderObjectToWidgetAdapter<RenderBox>(
......@@ -58,7 +58,7 @@ void attachWidgetTreeToRenderTree(RenderProxyBox container) {
],
),
onPressed: () {
value = value == null ? 0.1 : (value + 0.1) % 1.0;
value = value == null ? 0.1 : (value! + 0.1) % 1.0;
attachWidgetTreeToRenderTree(container);
},
),
......@@ -77,17 +77,17 @@ void attachWidgetTreeToRenderTree(RenderProxyBox container) {
).attachToRenderTree(owner, element);
}
Duration timeBase;
RenderTransform transformBox;
Duration? timeBase;
late RenderTransform transformBox;
void rotate(Duration timeStamp) {
timeBase ??= timeStamp;
final double delta = (timeStamp - timeBase).inMicroseconds.toDouble() / Duration.microsecondsPerSecond; // radians
final double delta = (timeStamp - timeBase!).inMicroseconds.toDouble() / Duration.microsecondsPerSecond; // radians
transformBox.setIdentity();
transformBox.rotateZ(delta);
owner.buildScope(element);
owner.buildScope(element!);
}
void main() {
......
......@@ -10,7 +10,7 @@ class SpinningSquare extends StatefulWidget {
}
class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProviderStateMixin {
AnimationController _animation;
late AnimationController _animation;
@override
void initState() {
......
......@@ -78,13 +78,7 @@ class StyledTextDemo extends StatefulWidget {
}
class _StyledTextDemoState extends State<StyledTextDemo> {
@override
void initState() {
super.initState();
_toText = toStyledText;
}
_TextTransformer _toText;
_TextTransformer _toText = toStyledText;
void _handleTap() {
setState(() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment