From 37bc722339b8f65c29bb7d21e5267ad2a4909ea2 Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Tue, 29 Jun 2021 11:49:27 -0700 Subject: [PATCH] Migrate dev/benchmarks/macrobenchmarks to null safety. (#85501) --- dev/benchmarks/macrobenchmarks/lib/main.dart | 4 +- .../lib/src/animated_image.dart | 8 +- .../lib/src/animated_placeholder.dart | 2 +- .../lib/src/animation_with_microtasks.dart | 2 +- .../lib/src/backdrop_filter.dart | 10 +- .../lib/src/color_filter_and_fade.dart | 26 +- .../macrobenchmarks/lib/src/cubic_bezier.dart | 22 +- .../macrobenchmarks/lib/src/cull_opacity.dart | 6 +- .../lib/src/filtered_child_animation.dart | 37 +- .../lib/src/fullscreen_textfield.dart | 2 +- .../lib/src/heavy_grid_view.dart | 4 +- .../lib/src/large_image_changer.dart | 6 +- .../macrobenchmarks/lib/src/large_images.dart | 6 +- .../lib/src/multi_widget_construction.dart | 14 +- .../lib/src/picture_cache.dart | 4 +- .../lib/src/post_backdrop_filter.dart | 8 +- .../lib/src/simple_animation.dart | 2 +- .../lib/src/simple_scroll.dart | 2 +- .../macrobenchmarks/lib/src/stack_size.dart | 6 +- .../macrobenchmarks/lib/src/text.dart | 2 +- .../lib/src/web/bench_build_image.dart | 13 +- .../web/bench_build_material_checkbox.dart | 6 +- .../src/web/bench_card_infinite_scroll.dart | 12 +- .../lib/src/web/bench_child_layers.dart | 12 +- .../bench_dynamic_clip_on_static_picture.dart | 6 +- .../web/bench_mouse_region_grid_hover.dart | 22 +- .../web/bench_mouse_region_grid_scroll.dart | 14 +- .../bench_mouse_region_mixed_grid_hover.dart | 24 +- .../bench_pageview_scroll_linethrough.dart | 12 +- .../lib/src/web/bench_paths_recording.dart | 422 +++++++++--------- .../lib/src/web/bench_picture_recording.dart | 4 +- .../web/bench_simple_lazy_text_scroll.dart | 14 +- .../lib/src/web/bench_text_layout.dart | 49 +- .../web/bench_text_out_of_picture_bounds.dart | 4 +- .../lib/src/web/bench_wrapbox_scroll.dart | 14 +- .../macrobenchmarks/lib/src/web/recorder.dart | 140 +++--- .../lib/src/web/test_data.dart | 12 +- .../macrobenchmarks/lib/web_benchmarks.dart | 44 +- dev/benchmarks/macrobenchmarks/pubspec.yaml | 2 +- .../macrobenchmarks/test/frame_policy.dart | 2 +- dev/benchmarks/macrobenchmarks/test/util.dart | 6 +- .../test_driver/animated_image.dart | 2 +- .../macrobenchmarks/test_driver/e2e_test.dart | 4 +- .../test_driver/frame_policy_test.dart | 6 +- .../test_driver/large_image_changer.dart | 2 +- .../test_driver/large_image_changer_test.dart | 2 +- .../test_driver/stack_size_perf_test.dart | 2 +- .../macrobenchmarks/test_driver/util.dart | 10 +- .../test_memory/heavy_gridview.dart | 4 +- .../test_memory/large_images.dart | 4 +- 50 files changed, 528 insertions(+), 515 deletions(-) diff --git a/dev/benchmarks/macrobenchmarks/lib/main.dart b/dev/benchmarks/macrobenchmarks/lib/main.dart index 645c43340e..8d46cd4099 100644 --- a/dev/benchmarks/macrobenchmarks/lib/main.dart +++ b/dev/benchmarks/macrobenchmarks/lib/main.dart @@ -31,7 +31,7 @@ const String kMacrobenchmarks = 'Macrobenchmarks'; void main() => runApp(const MacrobenchmarksApp()); class MacrobenchmarksApp extends StatelessWidget { - const MacrobenchmarksApp({Key key, this.initialRoute = '/'}) : super(key: key); + const MacrobenchmarksApp({Key? key, this.initialRoute = '/'}) : super(key: key); @override Widget build(BuildContext context) { @@ -68,7 +68,7 @@ class MacrobenchmarksApp extends StatelessWidget { } class HomePage extends StatelessWidget { - const HomePage({Key key}) : super(key: key); + const HomePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/animated_image.dart b/dev/benchmarks/macrobenchmarks/lib/src/animated_image.dart index fc68f9eec4..bc984fcf32 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/animated_image.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/animated_image.dart @@ -5,9 +5,9 @@ import 'package:flutter/material.dart'; class AnimatedImagePage extends StatelessWidget { - const AnimatedImagePage({Key key, this.onFrame}) : super(key: key); + const AnimatedImagePage({Key? key, this.onFrame}) : super(key: key); - final ValueChanged onFrame; + final ValueChanged? onFrame; @override Widget build(BuildContext context) { @@ -18,9 +18,9 @@ class AnimatedImagePage extends StatelessWidget { body: Image.asset( 'animated_images/animated_flutter_lgtm.gif', package: 'flutter_gallery_assets', - frameBuilder: (BuildContext context, Widget child, int/*?*/ frame, bool syncCall) { + frameBuilder: (BuildContext context, Widget child, int? frame, bool syncCall) { if (onFrame != null && frame != null) { - onFrame(frame); + onFrame?.call(frame); } return child; }, diff --git a/dev/benchmarks/macrobenchmarks/lib/src/animated_placeholder.dart b/dev/benchmarks/macrobenchmarks/lib/src/animated_placeholder.dart index 38090153b2..89b23a40dc 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/animated_placeholder.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/animated_placeholder.dart @@ -24,7 +24,7 @@ const String kBlueSquare = 'iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAASEl' /// A 10x10 grid of animated looping placeholder gifts that fade into a /// blue square. class AnimatedPlaceholderPage extends StatelessWidget { - const AnimatedPlaceholderPage({Key key}) : super(key: key); + const AnimatedPlaceholderPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/animation_with_microtasks.dart b/dev/benchmarks/macrobenchmarks/lib/src/animation_with_microtasks.dart index ef77237a1b..83cd77add2 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/animation_with_microtasks.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/animation_with_microtasks.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class AnimationWithMicrotasks extends StatefulWidget { - const AnimationWithMicrotasks({Key key}) : super(key: key); + const AnimationWithMicrotasks({Key? key}) : super(key: key); @override State createState() => _AnimationWithMicrotasksState(); diff --git a/dev/benchmarks/macrobenchmarks/lib/src/backdrop_filter.dart b/dev/benchmarks/macrobenchmarks/lib/src/backdrop_filter.dart index e8760302dd..7c2ce6dbe2 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/backdrop_filter.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/backdrop_filter.dart @@ -7,7 +7,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; class BackdropFilterPage extends StatefulWidget { - const BackdropFilterPage({Key key}) : super(key: key); + const BackdropFilterPage({Key? key}) : super(key: key); @override State createState() => _BackdropFilterPageState(); @@ -16,7 +16,7 @@ class BackdropFilterPage extends StatefulWidget { class _BackdropFilterPageState extends State with TickerProviderStateMixin { bool _blurGroup = false; bool _blurTexts = true; - AnimationController animation; + late AnimationController animation; @override void initState() { @@ -77,7 +77,7 @@ class _BackdropFilterPageState extends State with TickerProv child: Center( child: AnimatedBuilder( animation: animation, - builder: (BuildContext c, Widget w) { + builder: (BuildContext c, Widget? w) { final int val = (animation.value * 255).round(); return Container( width: 50, @@ -99,13 +99,13 @@ class _BackdropFilterPageState extends State with TickerProv const Text('Backdrop per txt:'), Checkbox( value: _blurTexts, - onChanged: (bool v) => setState(() { _blurTexts = v; }), + onChanged: (bool? v) => setState(() { _blurTexts = v ?? false; }), ), const SizedBox(width: 10), const Text('Backdrop grid:'), Checkbox( value: _blurGroup, - onChanged: (bool v) => setState(() { _blurGroup = v; }), + onChanged: (bool? v) => setState(() { _blurGroup = v ?? false; }), ), ], ), diff --git a/dev/benchmarks/macrobenchmarks/lib/src/color_filter_and_fade.dart b/dev/benchmarks/macrobenchmarks/lib/src/color_filter_and_fade.dart index 3ffa65a892..783ce964e6 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/color_filter_and_fade.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/color_filter_and_fade.dart @@ -9,7 +9,7 @@ import 'package:flutter/material.dart'; // This tests whether the Opacity layer raster cache works with color filters. // See https://github.com/flutter/flutter/issues/51975. class ColorFilterAndFadePage extends StatefulWidget { - const ColorFilterAndFadePage({Key key}) : super(key: key); + const ColorFilterAndFadePage({Key? key}) : super(key: key); @override State createState() => _ColorFilterAndFadePageState(); @@ -79,9 +79,9 @@ class _ColorFilterAndFadePageState extends State with Ti const Text('Use Color Filter:'), Checkbox( value: _useColorFilter, - onChanged: (bool value) { + onChanged: (bool? value) { setState(() { - _useColorFilter = value; + _useColorFilter = value ?? false; }); }, ), @@ -111,17 +111,23 @@ class _ColorFilterAndFadePageState extends State with Ti _initAnimation(); } - AnimationController _controller; - Animation _opacityAnimation; + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + late AnimationController _controller; + late Animation _opacityAnimation; bool _useColorFilter = true; } class _ShadowWidget extends StatelessWidget { const _ShadowWidget({ - @required this.width, - @required this.height, - @required this.useColorFilter, - @required this.shadow, + required this.width, + required this.height, + required this.useColorFilter, + required this.shadow, }); final double width; @@ -148,7 +154,7 @@ class _ShadowWidget extends StatelessWidget { } class _ShadowPainter extends CustomPainter { - const _ShadowPainter({this.useColorFilter, @required this.shadow}); + const _ShadowPainter({required this.useColorFilter, required this.shadow}); final bool useColorFilter; final Shadow shadow; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/cubic_bezier.dart b/dev/benchmarks/macrobenchmarks/lib/src/cubic_bezier.dart index 82e9e40ae8..9bb941ba3f 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/cubic_bezier.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/cubic_bezier.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; // Based on https://github.com/eseidelGoogle/bezier_perf/blob/master/lib/main.dart class CubicBezierPage extends StatelessWidget { - const CubicBezierPage({Key key}) : super(key: key); + const CubicBezierPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -24,7 +24,7 @@ class CubicBezierPage extends StatelessWidget { } class Bezier extends StatelessWidget { - const Bezier(this.color, this.scale, {Key key, this.blur = 0.0, this.delay = 0.0}) : super(key: key); + const Bezier(this.color, this.scale, {Key? key, this.blur = 0.0, this.delay = 0.0}) : super(key: key); final Color color; final double scale; @@ -79,7 +79,7 @@ class Bezier extends StatelessWidget { BezierPainter(Colors.grey, 0.0, _getLogoPath(), false), size: const Size(100.0, 100.0), ), - AnimatedBezier(color, scale, blur: blur, delay: delay), + AnimatedBezier(color, scale, blur: blur), ]); } } @@ -88,17 +88,16 @@ class PathDetail { PathDetail(this.path, {this.translate, this.rotation}); Path path; - List translate = []; - double rotation; + List? translate = []; + double? rotation; } class AnimatedBezier extends StatefulWidget { - const AnimatedBezier(this.color, this.scale, {Key key, this.blur = 0.0, this.delay}) : super(key: key); + const AnimatedBezier(this.color, this.scale, {Key? key, this.blur = 0.0}) : super(key: key); final Color color; final double scale; final double blur; - final double delay; @override State createState() => AnimatedBezierState(); @@ -113,9 +112,8 @@ class Point { class AnimatedBezierState extends State with SingleTickerProviderStateMixin { - double scale; - AnimationController controller; - CurvedAnimation curve; + late AnimationController controller; + late CurvedAnimation curve; bool isPlaying = false; List> pointList = >[ [], @@ -365,11 +363,11 @@ class BezierPainter extends CustomPainter { for (int i = 0; i < path.length; i++) { if (path[i].translate != null) { - canvas.translate(path[i].translate[0], path[i].translate[1]); + canvas.translate(path[i].translate![0], path[i].translate![1]); } if (path[i].rotation != null) { - canvas.rotate(path[i].rotation); + canvas.rotate(path[i].rotation!); } if (blur > 0) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/cull_opacity.dart b/dev/benchmarks/macrobenchmarks/lib/src/cull_opacity.dart index f3496f6f2b..664689cb42 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/cull_opacity.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/cull_opacity.dart @@ -5,15 +5,15 @@ import 'package:flutter/material.dart'; class CullOpacityPage extends StatefulWidget { - const CullOpacityPage({Key key}) : super(key: key); + const CullOpacityPage({Key? key}) : super(key: key); @override State createState() => _CullOpacityPageState(); } class _CullOpacityPageState extends State with SingleTickerProviderStateMixin { - Animation _offsetY; - AnimationController _controller; + late Animation _offsetY; + late AnimationController _controller; @override void initState() { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart b/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart index 87c0722205..97bcbf7e09 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart @@ -13,7 +13,7 @@ enum FilterType { class FilteredChildAnimationPage extends StatefulWidget { const FilteredChildAnimationPage(this.initialFilterType, { - Key key, + Key? key, this.initialComplexChild = true, this.initialUseRepaintBoundary = true, }) : super(key: key); @@ -27,13 +27,13 @@ class FilteredChildAnimationPage extends StatefulWidget { } class _FilteredChildAnimationPageState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; + late AnimationController _controller; final GlobalKey _childKey = GlobalKey(debugLabel: 'child to animate'); Offset _childCenter = Offset.zero; - FilterType _filterType; - bool _complexChild; - bool _useRepaintBoundary; + FilterType? _filterType; + late bool _complexChild; + late bool _useRepaintBoundary; @override void initState() { @@ -41,8 +41,8 @@ class _FilteredChildAnimationPageState extends State _filterType = widget.initialFilterType; _complexChild = widget.initialComplexChild; _useRepaintBoundary = widget.initialUseRepaintBoundary; - WidgetsBinding.instance.addPostFrameCallback((_) { - final RenderBox childBox = _childKey.currentContext.findRenderObject() as RenderBox; + WidgetsBinding.instance!.addPostFrameCallback((_) { + final RenderBox childBox = _childKey.currentContext!.findRenderObject()! as RenderBox; _childCenter = childBox.paintBounds.center; }); _controller = AnimationController(vsync: this, duration: const Duration(seconds: 2)); @@ -102,22 +102,23 @@ class _FilteredChildAnimationPageState extends State ); } - Widget _animate({Widget child, bool protectChild}) { + Widget _animate({required Widget child, required bool protectChild}) { if (_filterType == null) { _controller.reset(); return child; } + final FilterType filterType = _filterType!; _controller.repeat(); - Widget Function(BuildContext, Widget) builder; - switch (_filterType) { + Widget Function(BuildContext, Widget?) builder; + switch (filterType) { case FilterType.opacity: - builder = (BuildContext context, Widget child) => Opacity( + builder = (BuildContext context, Widget? child) => Opacity( opacity: (_controller.value * 2.0 - 1.0).abs(), child: child, ); break; case FilterType.rotateTransform: - builder = (BuildContext context, Widget child) => Transform( + builder = (BuildContext context, Widget? child) => Transform( transform: Matrix4.rotationZ(_controller.value * 2.0 * pi), alignment: Alignment.center, filterQuality: FilterQuality.low, @@ -125,7 +126,7 @@ class _FilteredChildAnimationPageState extends State ); break; case FilterType.rotateFilter: - builder = (BuildContext context, Widget child) => ImageFiltered( + builder = (BuildContext context, Widget? child) => ImageFiltered( imageFilter: ImageFilter.matrix(( Matrix4.identity() ..translate(_childCenter.dx, _childCenter.dy) @@ -176,17 +177,17 @@ class _FilteredChildAnimationPageState extends State const Text('Opacity:'), Checkbox( value: _filterType == FilterType.opacity, - onChanged: (bool b) => _setFilterType(FilterType.opacity, b), + onChanged: (bool? b) => _setFilterType(FilterType.opacity, b ?? false), ), const Text('Tx Rotate:'), Checkbox( value: _filterType == FilterType.rotateTransform, - onChanged: (bool b) => _setFilterType(FilterType.rotateTransform, b), + onChanged: (bool? b) => _setFilterType(FilterType.rotateTransform, b ?? false), ), const Text('IF Rotate:'), Checkbox( value: _filterType == FilterType.rotateFilter, - onChanged: (bool b) => _setFilterType(FilterType.rotateFilter, b), + onChanged: (bool? b) => _setFilterType(FilterType.rotateFilter, b ?? false), ), ], ), @@ -196,12 +197,12 @@ class _FilteredChildAnimationPageState extends State const Text('Complex child:'), Checkbox( value: _complexChild, - onChanged: (bool b) => setState(() => _complexChild = b), + onChanged: (bool? b) => setState(() => _complexChild = b ?? false), ), const Text('RPB on child:'), Checkbox( value: _useRepaintBoundary, - onChanged: (bool b) => setState(() => _useRepaintBoundary = b), + onChanged: (bool? b) => setState(() => _useRepaintBoundary = b ?? false), ), ], ), diff --git a/dev/benchmarks/macrobenchmarks/lib/src/fullscreen_textfield.dart b/dev/benchmarks/macrobenchmarks/lib/src/fullscreen_textfield.dart index 733604c198..305f59197b 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/fullscreen_textfield.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/fullscreen_textfield.dart @@ -48,7 +48,7 @@ const String textLotsOfText = 'Lorem ipsum dolor sit amet, consectetur ' 'ðŸĶŧ 👃 ðŸŦ€ ðŸŦ 🧠 ðŸĶ· ðŸĶī 👀 👁 👅 👄 💋 ðŸĐļ'; class TextFieldPage extends StatelessWidget { - const TextFieldPage({Key key}) : super(key: key); + const TextFieldPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/heavy_grid_view.dart b/dev/benchmarks/macrobenchmarks/lib/src/heavy_grid_view.dart index d42ea93932..27db044ea3 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/heavy_grid_view.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/heavy_grid_view.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class HeavyGridViewPage extends StatelessWidget { - const HeavyGridViewPage({Key key}) : super(key: key); + const HeavyGridViewPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -21,7 +21,7 @@ class HeavyWidget extends StatelessWidget { HeavyWidget(this.index) : super(key: ValueKey(index)); final int index; - final List _weight = List.filled(1000000, null); + final List _weight = List.filled(1000000, 0); @override Widget build(BuildContext context) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/large_image_changer.dart b/dev/benchmarks/macrobenchmarks/lib/src/large_image_changer.dart index e6f08da853..ac3536fae3 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/large_image_changer.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/large_image_changer.dart @@ -8,16 +8,16 @@ import 'package:flutter/material.dart'; /// Displays a new (from image cache's perspective) large image every 500ms. class LargeImageChangerPage extends StatefulWidget { - const LargeImageChangerPage({Key key}) : super(key: key); + const LargeImageChangerPage({Key? key}) : super(key: key); @override State createState() => _LargeImageChangerState(); } class _LargeImageChangerState extends State { - Timer _timer; + Timer? _timer; int imageIndex = 0; - ImageProvider currentImage; + late ImageProvider currentImage; @override void didChangeDependencies() { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/large_images.dart b/dev/benchmarks/macrobenchmarks/lib/src/large_images.dart index d8415a8c8b..7d6fa003c5 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/large_images.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/large_images.dart @@ -7,11 +7,11 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; class LargeImagesPage extends StatelessWidget { - const LargeImagesPage({Key key}) : super(key: key); + const LargeImagesPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { - final ImageCache imageCache = PaintingBinding.instance.imageCache; + final ImageCache imageCache = PaintingBinding.instance!.imageCache!; imageCache.maximumSize = 30; imageCache.maximumSizeBytes = 50 << 20; return GridView.builder( @@ -36,7 +36,7 @@ class DummyImage extends StatelessWidget { // creating many copies of the image to trigger the memory issue. return snapshot.data == null ? Container() - : Image.memory(snapshot.data.buffer.asUint8List()); + : Image.memory(snapshot.data!.buffer.asUint8List()); }, ); } diff --git a/dev/benchmarks/macrobenchmarks/lib/src/multi_widget_construction.dart b/dev/benchmarks/macrobenchmarks/lib/src/multi_widget_construction.dart index f28fa53554..05ed764157 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/multi_widget_construction.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/multi_widget_construction.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class MultiWidgetConstructTable extends StatefulWidget { - const MultiWidgetConstructTable(this.columnCount, this.rowCount, {Key key}) + const MultiWidgetConstructTable(this.columnCount, this.rowCount, {Key? key}) : super(key: key); final int columnCount; @@ -24,7 +24,7 @@ class _MultiWidgetConstructTableState extends State ]; int counter = 0; - AnimationController _controller; + late AnimationController _controller; @override void initState() { @@ -53,9 +53,9 @@ class _MultiWidgetConstructTableState extends State final double height = MediaQuery.of(context).size.height / widget.rowCount; final double colorPosition = _controller.value; final int c1Position = colorPosition.floor(); - final Color c1 = colorList[c1Position % colorList.length][900]; - final Color c2 = colorList[(c1Position + 1) % colorList.length][900]; - final Color baseColor = Color.lerp(c1, c2, colorPosition - c1Position); + final Color c1 = colorList[c1Position % colorList.length][900]!; + final Color c2 = colorList[(c1Position + 1) % colorList.length][900]!; + final Color baseColor = Color.lerp(c1, c2, colorPosition - c1Position)!; counter++; return Scaffold( body: Table( @@ -82,7 +82,7 @@ class _MultiWidgetConstructTableState extends State // This key forces rebuilding the element key: ValueKey(widgetCounter + label), color: Color.lerp( - Colors.white, baseColor, label / totalLength), + Colors.white, baseColor, label / totalLength)!, constraints: BoxConstraints.expand(height: height), child: Text('${widgetCounter + label}'), ); @@ -99,7 +99,7 @@ class _MultiWidgetConstructTableState extends State // This class is intended to break the original Widget tree class MyContainer extends StatelessWidget { - const MyContainer({this.color, this.child, this.constraints, Key key}) + const MyContainer({required this.color, required this.child, required this.constraints, Key? key}) : super(key: key); final Color color; final Widget child; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart b/dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart index ee9d3793ea..14c814893a 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class PictureCachePage extends StatelessWidget { - const PictureCachePage({Key key}) : super(key: key); + const PictureCachePage({Key? key}) : super(key: key); static const List kTabNames = ['1', '2', '3', '4', '5']; @@ -45,7 +45,7 @@ class PictureCachePage extends StatelessWidget { } class ListItem extends StatelessWidget { - const ListItem({Key key, this.index}) + const ListItem({Key? key, required this.index}) : super(key: key); final int index; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/post_backdrop_filter.dart b/dev/benchmarks/macrobenchmarks/lib/src/post_backdrop_filter.dart index b8eaf24dd0..f13736027e 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/post_backdrop_filter.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/post_backdrop_filter.dart @@ -7,7 +7,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; class PostBackdropFilterPage extends StatefulWidget { - const PostBackdropFilterPage({Key key}) : super(key: key); + const PostBackdropFilterPage({Key? key}) : super(key: key); @override State createState() => _PostBackdropFilterPageState(); @@ -15,7 +15,7 @@ class PostBackdropFilterPage extends StatefulWidget { class _PostBackdropFilterPageState extends State with TickerProviderStateMixin { bool _includeBackdropFilter = false; - AnimationController animation; + late AnimationController animation; @override void initState() { @@ -63,7 +63,7 @@ class _PostBackdropFilterPageState extends State with Ti child: Center( child: AnimatedBuilder( animation: animation, - builder: (BuildContext c, Widget w) { + builder: (BuildContext c, Widget? w) { final int val = (animation.value * 255).round(); return Container( width: 50, @@ -83,7 +83,7 @@ class _PostBackdropFilterPageState extends State with Ti Checkbox( key: const Key('bdf-checkbox'), // this key is used by the driver test value: _includeBackdropFilter, - onChanged: (bool v) => setState(() { _includeBackdropFilter = v; }), + onChanged: (bool? v) => setState(() { _includeBackdropFilter = v ?? false; }), ), MaterialButton( key: const Key('bdf-animate'), // this key is used by the driver test diff --git a/dev/benchmarks/macrobenchmarks/lib/src/simple_animation.dart b/dev/benchmarks/macrobenchmarks/lib/src/simple_animation.dart index 4fc5d18a07..221e274fea 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/simple_animation.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/simple_animation.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class SimpleAnimationPage extends StatelessWidget { - const SimpleAnimationPage({Key key}) : super(key: key); + const SimpleAnimationPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/simple_scroll.dart b/dev/benchmarks/macrobenchmarks/lib/src/simple_scroll.dart index 2050886dc0..41ea4cc215 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/simple_scroll.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/simple_scroll.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class SimpleScroll extends StatelessWidget { - const SimpleScroll({Key key}) : super(key: key); + const SimpleScroll({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/stack_size.dart b/dev/benchmarks/macrobenchmarks/lib/src/stack_size.dart index 821a795091..185d28872f 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/stack_size.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/stack_size.dart @@ -81,7 +81,7 @@ final GetStackPointerCallback getStackPointer = () { }(); class StackSizePage extends StatelessWidget { - const StackSizePage({Key key}) : super(key: key); + const StackSizePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -100,7 +100,7 @@ class StackSizePage extends StatelessWidget { } class ParentWidget extends StatelessWidget { - const ParentWidget({Key key}) : super(key: key); + const ParentWidget({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -110,7 +110,7 @@ class ParentWidget extends StatelessWidget { } class ChildWidget extends StatelessWidget { - const ChildWidget({this.parentStackSize, Key key}) : super(key: key); + const ChildWidget({required this.parentStackSize, Key? key}) : super(key: key); final int parentStackSize; @override diff --git a/dev/benchmarks/macrobenchmarks/lib/src/text.dart b/dev/benchmarks/macrobenchmarks/lib/src/text.dart index c89cb2d359..af18cae0db 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/text.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/text.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class TextPage extends StatelessWidget { - const TextPage({Key key}) : super(key: key); + const TextPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_image.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_image.dart index c4d5790241..d2773e6f40 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_image.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_image.dart @@ -52,7 +52,7 @@ class BenchBuildImage extends WidgetRecorder { } class _RotatingWidget extends StatefulWidget { - const _RotatingWidget({this.child, Key key}) : super(key: key); + const _RotatingWidget({required this.child, Key? key}) : super(key: key); final Widget child; @@ -61,7 +61,7 @@ class _RotatingWidget extends StatefulWidget { } class _RotatingWidgetState extends State<_RotatingWidget> with SingleTickerProviderStateMixin { - AnimationController controller; + late AnimationController controller; @override void initState() { @@ -72,11 +72,17 @@ class _RotatingWidgetState extends State<_RotatingWidget> with SingleTickerProvi )..repeat(); } + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return AnimatedBuilder( animation: controller, - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Transform( transform: Matrix4.identity()..rotateZ(2 * math.pi * controller.value), child: widget.child, @@ -84,5 +90,4 @@ class _RotatingWidgetState extends State<_RotatingWidget> with SingleTickerProvi }, ); } - } diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_material_checkbox.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_material_checkbox.dart index 8ced6c49c6..3bf1feaca2 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_material_checkbox.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_material_checkbox.dart @@ -14,7 +14,7 @@ class BenchBuildMaterialCheckbox extends WidgetBuildRecorder { static const String benchmarkName = 'build_material_checkbox'; - static bool _isChecked; + static bool? _isChecked; @override Widget createWidget() { @@ -33,7 +33,7 @@ class BenchBuildMaterialCheckbox extends WidgetBuildRecorder { Row _buildRow() { if (_isChecked == null) { _isChecked = true; - } else if (_isChecked) { + } else if (_isChecked!) { _isChecked = false; } else { _isChecked = null; @@ -45,7 +45,7 @@ class BenchBuildMaterialCheckbox extends WidgetBuildRecorder { child: Checkbox( value: _isChecked, tristate: true, - onChanged: (bool newValue) { + onChanged: (bool? newValue) { // Intentionally empty. }, ), diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_card_infinite_scroll.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_card_infinite_scroll.dart index d83a909146..a780bac0bf 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_card_infinite_scroll.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_card_infinite_scroll.dart @@ -35,7 +35,7 @@ class BenchCardInfiniteScroll extends WidgetRecorder { } class _InfiniteScrollCards extends StatefulWidget { - const _InfiniteScrollCards(this.initialOffset, this.finalOffset, {Key key}) : super(key: key); + const _InfiniteScrollCards(this.initialOffset, this.finalOffset, {Key? key}) : super(key: key); final double initialOffset; final double finalOffset; @@ -47,8 +47,8 @@ class _InfiniteScrollCards extends StatefulWidget { class _InfiniteScrollCardsState extends State<_InfiniteScrollCards> { static const Duration stepDuration = Duration(seconds: 20); - ScrollController scrollController; - double offset; + late ScrollController scrollController; + late double offset; @override void initState() { @@ -70,6 +70,12 @@ class _InfiniteScrollCardsState extends State<_InfiniteScrollCards> { }); } + @override + void dispose() { + scrollController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return ListView.builder( diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_child_layers.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_child_layers.dart index 404693e14e..df709d3230 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_child_layers.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_child_layers.dart @@ -31,10 +31,10 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder { /// is correctly pumping frames. double wobbleCounter = 0; - List _pictures; - Size windowSize; - Size cellSize; - Size rectSize; + late List _pictures; + late Size windowSize; + late Size cellSize; + late Size rectSize; @override Future setUpAll() async { @@ -55,7 +55,7 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder { } } - OffsetEngineLayer _rootLayer; + OffsetEngineLayer? _rootLayer; final Map _layers = {}; @override @@ -64,7 +64,7 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder { for (int row = 0; row < kRows; row++) { for (int col = 0; col < kColumns; col++) { final int layerId = 1000000 * row + col; - final OffsetEngineLayer oldLayer = _layers[layerId]; + final OffsetEngineLayer? oldLayer = _layers[layerId]; final double wobbleOffsetX = col * cellSize.width + (wobbleCounter - 5).abs(); final double offsetY = row * cellSize.height; // Retain every other layer, so we exercise the update path 50% of the diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_dynamic_clip_on_static_picture.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_dynamic_clip_on_static_picture.dart index b517f819d3..e69381166c 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_dynamic_clip_on_static_picture.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_dynamic_clip_on_static_picture.dart @@ -93,9 +93,9 @@ class BenchDynamicClipOnStaticPicture extends SceneBuilderRecorder { static const String benchmarkName = 'dynamic_clip_on_static_picture'; - Size screenSize; - Size clipSize; - Picture picture; + late Size screenSize; + late Size clipSize; + late Picture picture; double pictureVerticalOffset = 0.0; @override diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart index 794ab9385e..1b3250c290 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart @@ -14,7 +14,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'recorder.dart'; class _NestedMouseRegion extends StatelessWidget { - const _NestedMouseRegion({this.nests, this.child}); + const _NestedMouseRegion({required this.nests, required this.child}); final int nests; final Widget child; @@ -42,10 +42,10 @@ class BenchMouseRegionGridHover extends WidgetRecorder { static const String benchmarkName = 'bench_mouse_region_grid_hover'; - _Tester _tester; + late _Tester _tester; void handleDataPoint(Duration duration) { - profile.addDataPoint('hitTestDuration', duration, reported: true); + profile!.addDataPoint('hitTestDuration', duration, reported: true); } // Use a non-trivial border to force Web to switch painter @@ -66,7 +66,7 @@ class BenchMouseRegionGridHover extends WidgetRecorder { void frameDidDraw() { if (!started) { started = true; - SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) async { + SchedulerBinding.instance!.addPostFrameCallback((Duration timeStamp) async { _tester.start(); registerDidStop(_tester.stop); }); @@ -119,22 +119,22 @@ class BenchMouseRegionGridHover extends WidgetRecorder { class _UntilNextFrame { _UntilNextFrame._(); - static Completer _completer; + static Completer? _completer; static Future wait() { if (_UntilNextFrame._completer == null) { _UntilNextFrame._completer = Completer(); - SchedulerBinding.instance.addPostFrameCallback((_) { - _UntilNextFrame._completer.complete(null); + SchedulerBinding.instance!.addPostFrameCallback((_) { + _UntilNextFrame._completer!.complete(null); _UntilNextFrame._completer = null; }); } - return _UntilNextFrame._completer.future; + return _UntilNextFrame._completer!.future; } } class _Tester { - _Tester({this.onDataPoint}); + _Tester({required this.onDataPoint}); final ValueSetter onDataPoint; @@ -145,12 +145,12 @@ class _Tester { TestGesture get gesture { return _gesture ??= TestGesture( dispatcher: (PointerEvent event) async { - RendererBinding.instance.handlePointerEvent(event); + RendererBinding.instance!.handlePointerEvent(event); }, kind: PointerDeviceKind.mouse, ); } - TestGesture _gesture; + TestGesture? _gesture; Duration currentTime = Duration.zero; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart index a334b1b791..55eb9f6784 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart @@ -41,7 +41,7 @@ class BenchMouseRegionGridScroll extends WidgetRecorder { void frameDidDraw() { if (!started) { started = true; - SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) async { + SchedulerBinding.instance!.addPostFrameCallback((Duration timeStamp) async { _tester.start(); registerDidStop(_tester.stop); }); @@ -91,17 +91,17 @@ class BenchMouseRegionGridScroll extends WidgetRecorder { class _UntilNextFrame { _UntilNextFrame._(); - static Completer _completer; + static Completer? _completer; static Future wait() { if (_UntilNextFrame._completer == null) { _UntilNextFrame._completer = Completer(); - SchedulerBinding.instance.addPostFrameCallback((_) { - _UntilNextFrame._completer.complete(null); + SchedulerBinding.instance!.addPostFrameCallback((_) { + _UntilNextFrame._completer!.complete(null); _UntilNextFrame._completer = null; }); } - return _UntilNextFrame._completer.future; + return _UntilNextFrame._completer!.future; } } @@ -117,12 +117,12 @@ class _Tester { TestGesture get gesture { return _gesture ??= TestGesture( dispatcher: (PointerEvent event) async { - RendererBinding.instance.handlePointerEvent(event); + RendererBinding.instance!.handlePointerEvent(event); }, kind: PointerDeviceKind.mouse, ); } - TestGesture _gesture; + TestGesture? _gesture; Duration currentTime = Duration.zero; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_mixed_grid_hover.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_mixed_grid_hover.dart index b53aa458ef..85c20fa0f6 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_mixed_grid_hover.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_mixed_grid_hover.dart @@ -14,7 +14,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'recorder.dart'; class _NestedMouseRegion extends StatelessWidget { - const _NestedMouseRegion({this.nests, this.child}); + const _NestedMouseRegion({required this.nests, required this.child}); final int nests; final Widget child; @@ -33,7 +33,7 @@ class _NestedMouseRegion extends StatelessWidget { } class _NestedListener extends StatelessWidget { - const _NestedListener({this.nests, this.child}); + const _NestedListener({required this.nests, required this.child}); final int nests; final Widget child; @@ -61,10 +61,10 @@ class BenchMouseRegionMixedGridHover extends WidgetRecorder { static const String benchmarkName = 'bench_mouse_region_mixed_grid_hover'; - _Tester _tester; + late _Tester _tester; void handleDataPoint(Duration duration) { - profile.addDataPoint('hitTestDuration', duration, reported: true); + profile!.addDataPoint('hitTestDuration', duration, reported: true); } // Use a non-trivial border to force Web to switch painter @@ -85,7 +85,7 @@ class BenchMouseRegionMixedGridHover extends WidgetRecorder { void frameDidDraw() { if (!started) { started = true; - SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) async { + SchedulerBinding.instance!.addPostFrameCallback((Duration timeStamp) async { _tester.start(); registerDidStop(_tester.stop); }); @@ -141,22 +141,22 @@ class BenchMouseRegionMixedGridHover extends WidgetRecorder { class _UntilNextFrame { _UntilNextFrame._(); - static Completer _completer; + static Completer? _completer; static Future wait() { if (_UntilNextFrame._completer == null) { _UntilNextFrame._completer = Completer(); - SchedulerBinding.instance.addPostFrameCallback((_) { - _UntilNextFrame._completer.complete(null); + SchedulerBinding.instance!.addPostFrameCallback((_) { + _UntilNextFrame._completer!.complete(null); _UntilNextFrame._completer = null; }); } - return _UntilNextFrame._completer.future; + return _UntilNextFrame._completer!.future; } } class _Tester { - _Tester({this.onDataPoint}); + _Tester({required this.onDataPoint}); final ValueSetter onDataPoint; @@ -167,12 +167,12 @@ class _Tester { TestGesture get gesture { return _gesture ??= TestGesture( dispatcher: (PointerEvent event) async { - RendererBinding.instance.handlePointerEvent(event); + RendererBinding.instance!.handlePointerEvent(event); }, kind: PointerDeviceKind.mouse, ); } - TestGesture _gesture; + TestGesture? _gesture; Duration currentTime = Duration.zero; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_pageview_scroll_linethrough.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_pageview_scroll_linethrough.dart index 2bc1a6ab59..92dd2ffc2f 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_pageview_scroll_linethrough.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_pageview_scroll_linethrough.dart @@ -26,7 +26,7 @@ class BenchPageViewScrollLineThrough extends WidgetRecorder { } class _MyScrollContainer extends StatefulWidget { - const _MyScrollContainer({Key key}) : super(key: key); + const _MyScrollContainer({Key? key}) : super(key: key); @override State<_MyScrollContainer> createState() => _MyScrollContainerState(); @@ -35,7 +35,7 @@ class _MyScrollContainer extends StatefulWidget { class _MyScrollContainerState extends State<_MyScrollContainer> { static const Duration stepDuration = Duration(milliseconds: 500); - PageController pageController; + late PageController pageController; int pageNumber = 0; @override @@ -56,8 +56,8 @@ class _MyScrollContainerState extends State<_MyScrollContainer> { @override void dispose() { - super.dispose(); pageController.dispose(); + super.dispose(); } @override @@ -77,8 +77,8 @@ class _CustomPainter extends CustomPainter { _CustomPainter(this.text); final String text; - Paint _linePainter; - TextPainter _textPainter; + final Paint _linePainter = Paint(); + final TextPainter _textPainter = TextPainter(); static const double lineWidth = 0.5; @override @@ -91,14 +91,12 @@ class _CustomPainter extends CustomPainter { const double viewPadding = 5; const double circlePadding = 4; yPosition = viewPadding; - _textPainter = _textPainter ?? TextPainter(); _textPainter.textDirection = TextDirection.ltr; _textPainter.textWidthBasis = TextWidthBasis.longestLine; _textPainter.textScaleFactor = 1; const TextStyle textStyle = TextStyle(color: Colors.black87, fontSize: 13, fontFamily: 'Roboto'); - _linePainter = _linePainter ?? Paint(); _linePainter.isAntiAlias = true; for (int i = 0; i < 42; i++) { _linePainter.color = Colors.white; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_paths_recording.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_paths_recording.dart index 3b49345c68..ee55513849 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_paths_recording.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_paths_recording.dart @@ -7,218 +7,218 @@ import 'dart:ui'; // The code below was generated by modify several parts of the engine // May 2020 and running Flutter Gallery. -PathFillType gFillType; -Rect gBounds; -List allPaths; +late PathFillType gFillType; +late Rect gBounds; +late List allPaths; -Path path8; -Path path10; -Path path12; -Path path14; -Path path16; -Path path18; -Path path34; -Path path50; -Path path60; -Path path63; -Path path66; -Path path69; -Path path72; -Path path75; -Path path78; -Path path80; -Path path82; -Path path84; -Path path86; -Path path88; -Path path119; -Path path120; -Path path121; -Path path122; -Path path123; -Path path125; -Path path127; -Path path129; -Path path131; -Path path132; -Path path134; -Path path137; -Path path140; -Path path143; -Path path145; -Path path147; -Path path208; -Path path209; -Path path210; -Path path211; -Path path213; -Path path216; -Path path219; -Path path222; -Path path225; -Path path227; -Path path229; -Path path232; -Path path235; -Path path238; -Path path240; -Path path242; -Path path277; -Path path278; -Path path279; -Path path280; -Path path281; -Path path282; -Path path284; -Path path286; -Path path288; -Path path290; -Path path292; -Path path295; -Path path298; -Path path301; -Path path330; -Path path331; -Path path332; -Path path333; -Path path334; -Path path336; -Path path338; -Path path340; -Path path342; -Path path344; -Path path345; -Path path346; -Path path349; -Path path352; -Path path356; -Path path358; -Path path359; -Path path360; -Path path361; -Path path362; -Path path363; -Path path366; -Path path369; -Path path372; -Path path373; -Path path374; -Path path375; -Path path376; -Path path379; -Path path382; -Path path385; -Path path386; -Path path387; -Path path388; -Path path389; -Path path392; -Path path395; -Path path398; -Path path399; -Path path400; -Path path401; -Path path402; -Path path405; -Path path408; -Path path411; -Path path412; -Path path413; -Path path414; -Path path415; -Path path418; -Path path421; -Path path424; -Path path425; -Path path426; -Path path427; -Path path428; -Path path431; -Path path434; -Path path437; -Path path438; -Path path439; -Path path440; -Path path441; -Path path444; -Path path447; -Path path450; -Path path451; -Path path452; -Path path453; -Path path454; -Path path457; -Path path460; -Path path463; -Path path464; -Path path465; -Path path466; -Path path467; -Path path470; -Path path473; -Path path476; -Path path477; -Path path478; -Path path479; -Path path480; -Path path483; -Path path486; -Path path489; -Path path490; -Path path491; -Path path492; -Path path493; -Path path496; -Path path499; -Path path502; -Path path503; -Path path504; -Path path505; -Path path506; -Path path509; -Path path512; -Path path515; -Path path516; -Path path517; -Path path518; -Path path519; -Path path522; -Path path525; -Path path528; -Path path529; -Path path530; -Path path531; -Path path532; -Path path535; -Path path538; -Path path541; -Path path542; -Path path543; -Path path544; -Path path545; -Path path548; -Path path551; -Path path554; -Path path555; -Path path556; -Path path557; -Path path558; -Path path561; -Path path564; -Path path573; -Path path577; -Path path579; -Path path591; -Path path592; -Path path593; -Path path594; -Path path595; -Path path597; -Path path599; -Path path601; -Path path603; -Path path606; -Path path608; +late Path path8; +late Path path10; +late Path path12; +late Path path14; +late Path path16; +late Path path18; +late Path path34; +late Path path50; +late Path path60; +late Path path63; +late Path path66; +late Path path69; +late Path path72; +late Path path75; +late Path path78; +late Path path80; +late Path path82; +late Path path84; +late Path path86; +late Path path88; +late Path path119; +late Path path120; +late Path path121; +late Path path122; +late Path path123; +late Path path125; +late Path path127; +late Path path129; +late Path path131; +late Path path132; +late Path path134; +late Path path137; +late Path path140; +late Path path143; +late Path path145; +late Path path147; +late Path path208; +late Path path209; +late Path path210; +late Path path211; +late Path path213; +late Path path216; +late Path path219; +late Path path222; +late Path path225; +late Path path227; +late Path path229; +late Path path232; +late Path path235; +late Path path238; +late Path path240; +late Path path242; +late Path path277; +late Path path278; +late Path path279; +late Path path280; +late Path path281; +late Path path282; +late Path path284; +late Path path286; +late Path path288; +late Path path290; +late Path path292; +late Path path295; +late Path path298; +late Path path301; +late Path path330; +late Path path331; +late Path path332; +late Path path333; +late Path path334; +late Path path336; +late Path path338; +late Path path340; +late Path path342; +late Path path344; +late Path path345; +late Path path346; +late Path path349; +late Path path352; +late Path path356; +late Path path358; +late Path path359; +late Path path360; +late Path path361; +late Path path362; +late Path path363; +late Path path366; +late Path path369; +late Path path372; +late Path path373; +late Path path374; +late Path path375; +late Path path376; +late Path path379; +late Path path382; +late Path path385; +late Path path386; +late Path path387; +late Path path388; +late Path path389; +late Path path392; +late Path path395; +late Path path398; +late Path path399; +late Path path400; +late Path path401; +late Path path402; +late Path path405; +late Path path408; +late Path path411; +late Path path412; +late Path path413; +late Path path414; +late Path path415; +late Path path418; +late Path path421; +late Path path424; +late Path path425; +late Path path426; +late Path path427; +late Path path428; +late Path path431; +late Path path434; +late Path path437; +late Path path438; +late Path path439; +late Path path440; +late Path path441; +late Path path444; +late Path path447; +late Path path450; +late Path path451; +late Path path452; +late Path path453; +late Path path454; +late Path path457; +late Path path460; +late Path path463; +late Path path464; +late Path path465; +late Path path466; +late Path path467; +late Path path470; +late Path path473; +late Path path476; +late Path path477; +late Path path478; +late Path path479; +late Path path480; +late Path path483; +late Path path486; +late Path path489; +late Path path490; +late Path path491; +late Path path492; +late Path path493; +late Path path496; +late Path path499; +late Path path502; +late Path path503; +late Path path504; +late Path path505; +late Path path506; +late Path path509; +late Path path512; +late Path path515; +late Path path516; +late Path path517; +late Path path518; +late Path path519; +late Path path522; +late Path path525; +late Path path528; +late Path path529; +late Path path530; +late Path path531; +late Path path532; +late Path path535; +late Path path538; +late Path path541; +late Path path542; +late Path path543; +late Path path544; +late Path path545; +late Path path548; +late Path path551; +late Path path554; +late Path path555; +late Path path556; +late Path path557; +late Path path558; +late Path path561; +late Path path564; +late Path path573; +late Path path577; +late Path path579; +late Path path591; +late Path path592; +late Path path593; +late Path path594; +late Path path595; +late Path path597; +late Path path599; +late Path path601; +late Path path603; +late Path path606; +late Path path608; void createPaths() { allPaths = []; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_picture_recording.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_picture_recording.dart index 2f0092eaba..82dfd048ee 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_picture_recording.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_picture_recording.dart @@ -26,12 +26,12 @@ class BenchPictureRecording extends RawRecorder { /// Cached paint used for drawing. /// /// We want to avoid polluting the results with paint initialization logic. - Paint paint; + late Paint paint; /// A prelaid out and cached paragraph. /// /// This is cached to remove text layout time from the benchmark time. - Paragraph paragraph; + late Paragraph paragraph; @override Future setUpAll() async { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_simple_lazy_text_scroll.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_simple_lazy_text_scroll.dart index 9db9151bea..3dfcd4695e 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_simple_lazy_text_scroll.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_simple_lazy_text_scroll.dart @@ -56,9 +56,9 @@ class BenchSimpleLazyTextScroll extends WidgetRecorder { class _TestScrollingWidget extends StatefulWidget { const _TestScrollingWidget({ - @required this.initialScrollOffset, - @required this.scrollDistance, - @required this.scrollDuration, + required this.initialScrollOffset, + required this.scrollDistance, + required this.scrollDuration, }); final double initialScrollOffset; @@ -72,7 +72,7 @@ class _TestScrollingWidget extends StatefulWidget { } class _TestScrollingWidgetState extends State<_TestScrollingWidget> { - ScrollController scrollController; + late ScrollController scrollController; @override void initState() { @@ -98,6 +98,12 @@ class _TestScrollingWidgetState extends State<_TestScrollingWidget> { }); } + @override + void dispose() { + scrollController.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return ListView.builder( diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_layout.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_layout.dart index a439124b88..d52d111deb 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_layout.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_layout.dart @@ -31,7 +31,7 @@ class ParagraphGenerator { /// font-size so that the engine doesn't reuse a cached ruler. ui.Paragraph generate( String text, { - int maxLines, + int? maxLines, bool hasEllipsis = false, }) { final ui.ParagraphBuilder builder = ui.ParagraphBuilder(ui.ParagraphStyle( @@ -61,8 +61,8 @@ enum _TestMode { /// Sends a platform message to the web engine to enable/disable the usage of /// the canvas-based text measurement implementation. -void _setTestMode(_TestMode mode) { - bool useCanvasText; // null means do not force DOM or canvas, works for CanvasKit +void _setTestMode(_TestMode? mode) { + bool? useCanvasText; // null means do not force DOM or canvas, works for CanvasKit switch (mode) { case _TestMode.useDomTextLayout: useCanvasText = false; @@ -148,11 +148,11 @@ class BenchTextLayout extends RawRecorder { } void recordParagraphOperations({ - @required Profile profile, - @required ui.Paragraph paragraph, - @required String text, - @required String keyPrefix, - @required double maxWidth, + required Profile profile, + required ui.Paragraph paragraph, + required String text, + required String keyPrefix, + required double maxWidth, }) { profile.record('$keyPrefix.layout', () { paragraph.layout(ui.ParagraphConstraints(width: maxWidth)); @@ -277,7 +277,7 @@ class BenchBuildColorsGrid extends WidgetBuildRecorder { // updates the value of [showWidget] in preparation for the next frame. // TODO(yjbanov): https://github.com/flutter/flutter/issues/53877 if (showWidget && _mode != _TestMode.useCanvasKit) { - profile.addDataPoint( + profile!.addDataPoint( 'text_layout', Duration(microseconds: _textLayoutMicros.toInt()), reported: true, @@ -299,15 +299,13 @@ class BenchBuildColorsGrid extends WidgetBuildRecorder { const double kColorItemHeight = 48.0; class Palette { - Palette({this.name, this.primary, this.accent, this.threshold = 900}); + Palette({required this.name, required this.primary, this.accent, this.threshold = 900}); final String name; final MaterialColor primary; - final MaterialAccentColor accent; + final MaterialAccentColor? accent; final int threshold; // titles for indices > threshold are white, otherwise black - - bool get isValid => name != null && primary != null && threshold != null; } final List allPalettes = [ @@ -390,9 +388,9 @@ final List allPalettes = [ class ColorItem extends StatelessWidget { const ColorItem({ - Key key, - @required this.index, - @required this.color, + Key? key, + required this.index, + required this.color, this.prefix = '', }) : assert(index != null), assert(color != null), @@ -432,11 +430,10 @@ class ColorItem extends StatelessWidget { } class PaletteTabView extends StatelessWidget { - PaletteTabView({ - Key key, - @required this.colors, - }) : assert(colors != null && colors.isValid), - super(key: key); + const PaletteTabView({ + Key? key, + required this.colors, + }) : super(key: key); final Palette colors; @@ -458,9 +455,9 @@ class PaletteTabView extends StatelessWidget { Widget build(BuildContext context) { final TextTheme textTheme = Theme.of(context).textTheme; final TextStyle whiteTextStyle = - textTheme.bodyText2.copyWith(color: Colors.white); + textTheme.bodyText2!.copyWith(color: Colors.white); final TextStyle blackTextStyle = - textTheme.bodyText2.copyWith(color: Colors.black); + textTheme.bodyText2!.copyWith(color: Colors.black); return Scrollbar( child: ListView( itemExtent: kColorItemHeight, @@ -468,7 +465,7 @@ class PaletteTabView extends StatelessWidget { ...primaryKeys.map((int index) { return DefaultTextStyle( style: index > colors.threshold ? whiteTextStyle : blackTextStyle, - child: ColorItem(index: index, color: colors.primary[index]), + child: ColorItem(index: index, color: colors.primary[index]!), ); }), if (colors.accent != null) @@ -477,7 +474,7 @@ class PaletteTabView extends StatelessWidget { style: index > colors.threshold ? whiteTextStyle : blackTextStyle, child: ColorItem( - index: index, color: colors.accent[index], prefix: 'A'), + index: index, color: colors.accent![index]!, prefix: 'A'), ); }), ], @@ -487,7 +484,7 @@ class PaletteTabView extends StatelessWidget { } class ColorsDemo extends StatelessWidget { - const ColorsDemo({Key key}) : super(key: key); + const ColorsDemo({Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_out_of_picture_bounds.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_out_of_picture_bounds.dart index d1a8c3d462..3585f99499 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_out_of_picture_bounds.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_text_out_of_picture_bounds.dart @@ -54,8 +54,8 @@ class BenchTextOutOfPictureBounds extends SceneBuilderRecorder { static const String benchmarkName = 'text_out_of_picture_bounds'; - List singleLineParagraphs; - List multiLineParagraphs; + late List singleLineParagraphs; + late List multiLineParagraphs; @override void onDrawFrame(SceneBuilder sceneBuilder) { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_wrapbox_scroll.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_wrapbox_scroll.dart index 1eda108cd0..785f5fa251 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_wrapbox_scroll.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_wrapbox_scroll.dart @@ -29,16 +29,14 @@ class BenchWrapBoxScroll extends WidgetRecorder { } class MyHomePage extends StatefulWidget { - const MyHomePage({Key key, this.title}) : super(key: key); - - final String title; + const MyHomePage({Key? key}) : super(key: key); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { - ScrollController scrollController; + late ScrollController scrollController; int block = 0; static const Duration stepDuration = Duration(milliseconds: 500); static const double stepDistance = 400; @@ -61,8 +59,8 @@ class _MyHomePageState extends State { @override void dispose() { - super.dispose(); scrollController.dispose(); + super.dispose(); } @override @@ -84,7 +82,7 @@ class _MyHomePageState extends State { } class ProductPreview extends StatelessWidget { - const ProductPreview(this.previewIndex, {Key key}) : super(key: key); + const ProductPreview(this.previewIndex, {Key? key}) : super(key: key); final int previewIndex; @@ -143,8 +141,8 @@ class ProductPreview extends StatelessWidget { class ProductOption extends StatelessWidget { const ProductOption({ - Key key, - @required this.optionText, + Key? key, + required this.optionText, }) : super(key: key); final String optionText; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart index 69c192767a..e3e4637c68 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart @@ -63,7 +63,7 @@ class Runner { /// /// All arguments must not be null. Runner({ - @required this.recorder, + required this.recorder, this.setUpAllDidRun = _dummyAsyncVoidCallback, this.tearDownAllWillRun = _dummyAsyncVoidCallback, }); @@ -113,13 +113,13 @@ abstract class Recorder { /// Returns the recorded profile. /// /// This value is only available while the benchmark is running. - Profile get profile; + Profile? get profile; /// Whether the benchmark should continue running. /// /// Returns `false` if the benchmark collected enough data and it's time to /// stop. - bool shouldContinue() => profile.shouldContinue(); + bool shouldContinue() => profile?.shouldContinue() ?? true; /// Called once before all runs of this benchmark recorder. /// @@ -161,7 +161,7 @@ abstract class Recorder { /// } /// ``` abstract class RawRecorder extends Recorder { - RawRecorder({@required String name}) : super._(name, false); + RawRecorder({required String name}) : super._(name, false); /// The body of the benchmark. /// @@ -169,8 +169,8 @@ abstract class RawRecorder extends Recorder { void body(Profile profile); @override - Profile get profile => _profile; - Profile _profile; + Profile? get profile => _profile; + Profile? _profile; @override @nonVirtual @@ -178,9 +178,9 @@ abstract class RawRecorder extends Recorder { _profile = Profile(name: name); do { await Future.delayed(Duration.zero); - body(_profile); + body(_profile!); } while (shouldContinue()); - return _profile; + return _profile!; } } @@ -210,11 +210,11 @@ abstract class RawRecorder extends Recorder { /// } /// ``` abstract class SceneBuilderRecorder extends Recorder { - SceneBuilderRecorder({@required String name}) : super._(name, true); + SceneBuilderRecorder({required String name}) : super._(name, true); @override - Profile get profile => _profile; - Profile _profile; + Profile? get profile => _profile; + Profile? _profile; /// Called from [dart:ui.PlatformDispatcher.onBeginFrame]. @mustCallSuper @@ -235,7 +235,7 @@ abstract class SceneBuilderRecorder extends Recorder { window.onBeginFrame = (_) { try { - startMeasureFrame(profile); + startMeasureFrame(profile!); onBeginFrame(); } catch (error, stackTrace) { profileCompleter.completeError(error, stackTrace); @@ -244,12 +244,12 @@ abstract class SceneBuilderRecorder extends Recorder { }; window.onDrawFrame = () { try { - _profile.record('drawFrameDuration', () { + _profile!.record('drawFrameDuration', () { final SceneBuilder sceneBuilder = SceneBuilder(); onDrawFrame(sceneBuilder); - _profile.record('sceneBuildDuration', () { + _profile!.record('sceneBuildDuration', () { final Scene scene = sceneBuilder.build(); - _profile.record('windowRenderDuration', () { + _profile!.record('windowRenderDuration', () { window.render(scene); }, reported: false); }, reported: false); @@ -334,7 +334,7 @@ abstract class SceneBuilderRecorder extends Recorder { /// ``` abstract class WidgetRecorder extends Recorder implements FrameRecorder { WidgetRecorder({ - @required String name, + required String name, this.useCustomWarmUp = false, }) : super._(name, true); @@ -352,18 +352,18 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder { } @override - Profile profile; - Completer _runCompleter; + Profile? profile; + Completer? _runCompleter; /// Whether to delimit warm-up frames in a custom way. final bool useCustomWarmUp; - Stopwatch _drawFrameStopwatch; + late Stopwatch _drawFrameStopwatch; @override @mustCallSuper void frameWillDraw() { - startMeasureFrame(profile); + startMeasureFrame(profile!); _drawFrameStopwatch = Stopwatch()..start(); } @@ -371,20 +371,20 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder { @mustCallSuper void frameDidDraw() { endMeasureFrame(); - profile.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed, reported: true); + profile!.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed, reported: true); if (shouldContinue()) { window.scheduleFrame(); } else { for (final VoidCallback fn in _didStopCallbacks) fn(); - _runCompleter.complete(); + _runCompleter!.complete(); } } @override - void _onError(dynamic error, StackTrace stackTrace) { - _runCompleter.completeError(error, stackTrace); + void _onError(Object error, StackTrace? stackTrace) { + _runCompleter!.completeError(error, stackTrace); } @override @@ -413,7 +413,7 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder { binding._beginRecording(this, widget); try { - await _runCompleter.future; + await _runCompleter!.future; return localProfile; } finally { stopListeningToEngineBenchmarkValues(kProfilePrerollFrame); @@ -432,7 +432,7 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder { /// performance of frames that render the widget and ignoring the frames that /// clear the screen. abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { - WidgetBuildRecorder({@required String name}) : super._(name, true); + WidgetBuildRecorder({required String name}) : super._(name, true); /// Creates a widget to be benchmarked. /// @@ -448,10 +448,10 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { } @override - Profile profile; - Completer _runCompleter; + Profile? profile; + Completer? _runCompleter; - Stopwatch _drawFrameStopwatch; + late Stopwatch _drawFrameStopwatch; /// Whether in this frame we should call [createWidget] and render it. /// @@ -459,9 +459,9 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { bool showWidget = true; /// The state that hosts the widget under test. - _WidgetBuildRecorderHostState _hostState; + late _WidgetBuildRecorderHostState _hostState; - Widget _getWidgetForFrame() { + Widget? _getWidgetForFrame() { if (showWidget) { return createWidget(); } else { @@ -473,7 +473,7 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { @mustCallSuper void frameWillDraw() { if (showWidget) { - startMeasureFrame(profile); + startMeasureFrame(profile!); _drawFrameStopwatch = Stopwatch()..start(); } } @@ -484,7 +484,7 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { // Only record frames that show the widget. if (showWidget) { endMeasureFrame(); - profile.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed, reported: true); + profile!.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed, reported: true); } if (shouldContinue()) { @@ -493,13 +493,13 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { } else { for (final VoidCallback fn in _didStopCallbacks) fn(); - _runCompleter.complete(); + _runCompleter!.complete(); } } @override - void _onError(dynamic error, StackTrace stackTrace) { - _runCompleter.completeError(error, stackTrace); + void _onError(Object error, StackTrace? stackTrace) { + _runCompleter!.completeError(error, stackTrace); } @override @@ -511,7 +511,7 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { binding._beginRecording(this, _WidgetBuildRecorderHost(this)); try { - await _runCompleter.future; + await _runCompleter!.future; return localProfile; } finally { _runCompleter = null; @@ -578,11 +578,11 @@ class Timeseries { /// The number of frames ignored as warm-up frames, used only /// when [useCustomWarmUp] is true. - int _warmUpFrameCount; + int? _warmUpFrameCount; /// The number of frames ignored as warm-up frames. int get warmUpFrameCount => useCustomWarmUp - ? _warmUpFrameCount + ? _warmUpFrameCount! : count - _kMeasuredSampleCount; /// List of all the values that have been recorded. @@ -664,7 +664,7 @@ class Timeseries { } /// Adds a value to this timeseries. - void add(double value, {@required bool isWarmUpValue}) { + void add(double value, {required bool isWarmUpValue}) { if (value < 0.0) { throw StateError( 'Timeseries $name: negative metric values are not supported. Got: $value', @@ -672,7 +672,7 @@ class Timeseries { } _allValues.add(value); if (useCustomWarmUp && isWarmUpValue) { - _warmUpFrameCount += 1; + _warmUpFrameCount = (_warmUpFrameCount ?? 0) + 1; } } } @@ -683,15 +683,15 @@ class Timeseries { @sealed class TimeseriesStats { const TimeseriesStats({ - @required this.name, - @required this.average, - @required this.outlierCutOff, - @required this.outlierAverage, - @required this.standardDeviation, - @required this.noise, - @required this.cleanSampleCount, - @required this.outlierSampleCount, - @required this.samples, + required this.name, + required this.average, + required this.outlierCutOff, + required this.outlierAverage, + required this.standardDeviation, + required this.noise, + required this.cleanSampleCount, + required this.outlierSampleCount, + required this.samples, }); /// The label used to refer to the corresponding timeseries. @@ -764,9 +764,9 @@ class TimeseriesStats { @sealed class AnnotatedSample { const AnnotatedSample({ - @required this.magnitude, - @required this.isOutlier, - @required this.isWarmUpValue, + required this.magnitude, + required this.isOutlier, + required this.isWarmUpValue, }); /// The non-negative raw result of the measurement. @@ -787,7 +787,7 @@ class AnnotatedSample { /// Base class for a profile collected from running a benchmark. class Profile { - Profile({@required this.name, this.useCustomWarmUp = false}) + Profile({required this.name, this.useCustomWarmUp = false}) : assert(name != null), _isWarmingUp = useCustomWarmUp; @@ -824,7 +824,7 @@ class Profile { final Map extraData = {}; /// Invokes [callback] and records the duration of its execution under [key]. - Duration record(String key, VoidCallback callback, { @required bool reported }) { + Duration record(String key, VoidCallback callback, { required bool reported }) { final Duration duration = timeAction(callback); addDataPoint(key, duration, reported: reported); return duration; @@ -836,7 +836,7 @@ class Profile { /// /// Set [reported] to `false` to store the data, but not show it on the /// dashboard UI. - void addDataPoint(String key, Duration duration, { @required bool reported }) { + void addDataPoint(String key, Duration duration, { required bool reported }) { scoreData.putIfAbsent( key, () => Timeseries(key, reported, useCustomWarmUp: useCustomWarmUp), @@ -860,7 +860,7 @@ class Profile { // We have recorded something, but do we have enough samples? If every // timeseries has collected enough samples, stop the benchmark. - return !scoreData.keys.every((String key) => scoreData[key].count >= kTotalSampleCount); + return !scoreData.keys.every((String key) => scoreData[key]!.count >= kTotalSampleCount); } /// Returns a JSON representation of the profile that will be sent to the @@ -873,7 +873,7 @@ class Profile { }; for (final String key in scoreData.keys) { - final Timeseries timeseries = scoreData[key]; + final Timeseries timeseries = scoreData[key]!; if (timeseries.isReported) { scoreKeys.add('$key.average'); @@ -900,7 +900,7 @@ class Profile { final StringBuffer buffer = StringBuffer(); buffer.writeln('name: $name'); for (final String key in scoreData.keys) { - final Timeseries timeseries = scoreData[key]; + final Timeseries timeseries = scoreData[key]!; final TimeseriesStats stats = timeseries.computeStats(); buffer.writeln(stats.toString()); } @@ -967,7 +967,7 @@ abstract class FrameRecorder { /// Reports an error. /// /// The implementation is expected to halt benchmark execution as soon as possible. - void _onError(dynamic error, StackTrace stackTrace); + void _onError(Object error, StackTrace? stackTrace); } /// A variant of [WidgetsBinding] that collaborates with a [Recorder] to decide @@ -992,10 +992,10 @@ class _RecordingWidgetsBinding extends BindingBase if (WidgetsBinding.instance == null) { _RecordingWidgetsBinding(); } - return WidgetsBinding.instance as _RecordingWidgetsBinding; + return WidgetsBinding.instance! as _RecordingWidgetsBinding; } - FrameRecorder _recorder; + FrameRecorder? _recorder; bool _hasErrored = false; /// To short-circuit all frame lifecycle methods when the benchmark has @@ -1008,7 +1008,7 @@ class _RecordingWidgetsBinding extends BindingBase 'Cannot call _RecordingWidgetsBinding._beginRecording more than once', ); } - final FlutterExceptionHandler originalOnError = FlutterError.onError; + final FlutterExceptionHandler? originalOnError = FlutterError.onError; recorder.registerDidStop(() { _benchmarkStopped = true; @@ -1017,22 +1017,22 @@ class _RecordingWidgetsBinding extends BindingBase // Fail hard and fast on errors. Benchmarks should not have any errors. FlutterError.onError = (FlutterErrorDetails details) { _haltBenchmarkWithError(details.exception, details.stack); - originalOnError(details); + originalOnError?.call(details); }; _recorder = recorder; runApp(widget); } - void _haltBenchmarkWithError(dynamic error, StackTrace stackTrace) { + void _haltBenchmarkWithError(Object error, StackTrace? stackTrace) { if (_hasErrored) { return; } - _recorder._onError(error, stackTrace); + _recorder?._onError(error, stackTrace); _hasErrored = true; } @override - void handleBeginFrame(Duration rawTimeStamp) { + void handleBeginFrame(Duration? rawTimeStamp) { // Don't keep on truckin' if there's an error or the benchmark has stopped. if (_hasErrored || _benchmarkStopped) { return; @@ -1061,9 +1061,9 @@ class _RecordingWidgetsBinding extends BindingBase return; } try { - _recorder.frameWillDraw(); + _recorder?.frameWillDraw(); super.handleDrawFrame(); - _recorder.frameDidDraw(); + _recorder?.frameDidDraw(); } catch (error, stackTrace) { _haltBenchmarkWithError(error, stackTrace); rethrow; @@ -1189,7 +1189,7 @@ void stopListeningToEngineBenchmarkValues(String name) { // // If there are no listeners registered for [name], ignores the value. void _dispatchEngineBenchmarkValue(String name, double value) { - final EngineBenchmarkValueListener listener = _engineBenchmarkListeners[name]; + final EngineBenchmarkValueListener? listener = _engineBenchmarkListeners[name]; if (listener != null) { listener(value); } diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/test_data.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/test_data.dart index 688dbca8b1..dba4aad268 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/test_data.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/test_data.dart @@ -5,8 +5,6 @@ import 'dart:math' as math; import 'dart:ui'; -import 'package:meta/meta.dart'; - // Used to randomize data. // // Using constant seed for reproducibility. @@ -34,11 +32,11 @@ final List lipsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing /// Generates strings and builds pre-laid out paragraphs to be used by /// benchmarks. List generateLaidOutParagraphs({ - @required int paragraphCount, - @required int minWordCountPerParagraph, - @required int maxWordCountPerParagraph, - @required double widthConstraint, - @required Color color, + required int paragraphCount, + required int minWordCountPerParagraph, + required int maxWordCountPerParagraph, + required double widthConstraint, + required Color color, }) { final List strings = []; int wordPointer = 0; // points to the next word in lipsum to extract diff --git a/dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart b/dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart index 727a77efbc..72778b22a3 100644 --- a/dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart +++ b/dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart @@ -93,7 +93,7 @@ Future main() async { } Future _runBenchmark(String benchmarkName) async { - final RecorderFactory recorderFactory = benchmarks[benchmarkName]; + final RecorderFactory? recorderFactory = benchmarks[benchmarkName]; if (recorderFactory == null) { _fallbackToManual('Benchmark $benchmarkName not found.'); @@ -145,7 +145,7 @@ Future _runBenchmark(String benchmarkName) async { } void _fallbackToManual(String error) { - html.document.body.appendHtml(''' + html.document.body!.appendHtml('''

$error

@@ -163,9 +163,9 @@ void _fallbackToManual(String error) { ''', validator: html.NodeValidatorBuilder()..allowHtml5()..allowInlineStyles()); for (final String benchmarkName in benchmarks.keys) { - final html.Element button = html.document.querySelector('#$benchmarkName'); + final html.Element button = html.document.querySelector('#$benchmarkName')!; button.addEventListener('click', (_) { - final html.Element manualPanel = html.document.querySelector('#manual-panel'); + final html.Element? manualPanel = html.document.querySelector('#manual-panel'); manualPanel?.remove(); _runBenchmark(benchmarkName); }); @@ -174,14 +174,14 @@ void _fallbackToManual(String error) { /// Visualizes results on the Web page for manual inspection. void _printResultsToScreen(Profile profile) { - html.document.body.remove(); + html.document.body!.remove(); html.document.body = html.BodyElement(); - html.document.body.appendHtml('

${profile.name}

'); + html.document.body!.appendHtml('

${profile.name}

'); profile.scoreData.forEach((String scoreKey, Timeseries timeseries) { - html.document.body.appendHtml('

$scoreKey

'); - html.document.body.appendHtml('
${timeseries.computeStats()}
'); - html.document.body.append(TimeseriesVisualization(timeseries).render()); + html.document.body!.appendHtml('

$scoreKey

'); + html.document.body!.appendHtml('
${timeseries.computeStats()}
'); + html.document.body!.append(TimeseriesVisualization(timeseries).render()); }); } @@ -190,7 +190,7 @@ class TimeseriesVisualization { TimeseriesVisualization(this._timeseries) { _stats = _timeseries.computeStats(); _canvas = html.CanvasElement(); - _screenWidth = html.window.screen.width; + _screenWidth = html.window.screen!.width!; _canvas.width = _screenWidth; _canvas.height = (_kCanvasHeight * html.window.devicePixelRatio).round(); _canvas.style @@ -211,13 +211,13 @@ class TimeseriesVisualization { static const double _kCanvasHeight = 200; final Timeseries _timeseries; - TimeseriesStats _stats; - html.CanvasElement _canvas; - html.CanvasRenderingContext2D _ctx; - int _screenWidth; + late TimeseriesStats _stats; + late html.CanvasElement _canvas; + late html.CanvasRenderingContext2D _ctx; + late int _screenWidth; // Used to normalize benchmark values to chart height. - double _maxValueChartRange; + late double _maxValueChartRange; /// Converts a sample value to vertical canvas coordinates. /// @@ -300,7 +300,7 @@ class LocalBenchmarkServerClient { /// This happens when you run benchmarks using plain `flutter run` rather than /// devicelab test harness. The test harness spins up a special server that /// provides API for automatically picking the next benchmark to run. - bool isInManualMode; + bool isInManualMode = false; /// Asks the local server for the name of the next benchmark to run. /// @@ -323,7 +323,7 @@ class LocalBenchmarkServerClient { } isInManualMode = false; - return request.responseText; + return request.responseText!; } void _checkNotManualMode() { @@ -405,11 +405,11 @@ class LocalBenchmarkServerClient { /// crash on 404, which we use to detect `flutter run`. Future _requestXhr( String url, { - String method, - bool withCredentials, - String responseType, - String mimeType, - Map requestHeaders, + String? method, + bool? withCredentials, + String? responseType, + String? mimeType, + Map? requestHeaders, dynamic sendData, }) { final Completer completer = Completer(); diff --git a/dev/benchmarks/macrobenchmarks/pubspec.yaml b/dev/benchmarks/macrobenchmarks/pubspec.yaml index eb3e8915a0..518886ded1 100644 --- a/dev/benchmarks/macrobenchmarks/pubspec.yaml +++ b/dev/benchmarks/macrobenchmarks/pubspec.yaml @@ -2,7 +2,7 @@ name: macrobenchmarks description: Performance benchmarks using flutter drive. environment: - sdk: ">=2.2.2 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: diff --git a/dev/benchmarks/macrobenchmarks/test/frame_policy.dart b/dev/benchmarks/macrobenchmarks/test/frame_policy.dart index 2f34f83c0d..7e13444b54 100644 --- a/dev/benchmarks/macrobenchmarks/test/frame_policy.dart +++ b/dev/benchmarks/macrobenchmarks/test/frame_policy.dart @@ -74,7 +74,7 @@ void main() { frameCount = 0; delays = await tester.handlePointerEventRecord(records); await tester.pumpAndSettle(); - binding.reportData['fullyLive'] = _summarizeResult(frameCount, delays); + binding.reportData!['fullyLive'] = _summarizeResult(frameCount, delays); await tester.idle(); }, ); diff --git a/dev/benchmarks/macrobenchmarks/test/util.dart b/dev/benchmarks/macrobenchmarks/test/util.dart index e99bfa4f7e..3905a60de7 100644 --- a/dev/benchmarks/macrobenchmarks/test/util.dart +++ b/dev/benchmarks/macrobenchmarks/test/util.dart @@ -13,10 +13,10 @@ typedef ControlCallback = Future Function(WidgetController controller); void macroPerfTestE2E( String testName, String routeName, { - Duration pageDelay, + Duration? pageDelay, Duration duration = const Duration(seconds: 3), - ControlCallback body, - ControlCallback setup, + ControlCallback? body, + ControlCallback? setup, }) { final WidgetsBinding _binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); assert(_binding is IntegrationTestWidgetsFlutterBinding); diff --git a/dev/benchmarks/macrobenchmarks/test_driver/animated_image.dart b/dev/benchmarks/macrobenchmarks/test_driver/animated_image.dart index 9a27e0944a..f91752152a 100644 --- a/dev/benchmarks/macrobenchmarks/test_driver/animated_image.dart +++ b/dev/benchmarks/macrobenchmarks/test_driver/animated_image.dart @@ -15,7 +15,7 @@ import 'package:macrobenchmarks/src/animated_image.dart'; /// set number of image frames to render. Future main() async { final Completer waiter = Completer(); - enableFlutterDriverExtension(handler: (String request) async { + enableFlutterDriverExtension(handler: (String? request) async { if (request != 'waitForAnimation') { throw UnsupportedError('Unrecognized request $request'); } diff --git a/dev/benchmarks/macrobenchmarks/test_driver/e2e_test.dart b/dev/benchmarks/macrobenchmarks/test_driver/e2e_test.dart index b6b9b8bc93..7470729666 100644 --- a/dev/benchmarks/macrobenchmarks/test_driver/e2e_test.dart +++ b/dev/benchmarks/macrobenchmarks/test_driver/e2e_test.dart @@ -5,9 +5,9 @@ import 'package:integration_test/integration_test_driver.dart' as driver; Future main() => driver.integrationDriver( - responseDataCallback: (Map data) async { + responseDataCallback: (Map? data) async { await driver.writeResponseData( - data['performance'] as Map, + data?['performance'] as Map, testOutputFilename: 'e2e_perf_summary', ); } diff --git a/dev/benchmarks/macrobenchmarks/test_driver/frame_policy_test.dart b/dev/benchmarks/macrobenchmarks/test_driver/frame_policy_test.dart index 77aa56aeb7..9686e54243 100644 --- a/dev/benchmarks/macrobenchmarks/test_driver/frame_policy_test.dart +++ b/dev/benchmarks/macrobenchmarks/test_driver/frame_policy_test.dart @@ -7,11 +7,11 @@ import 'dart:io'; import 'package:integration_test/integration_test_driver.dart' as driver; Future main() => driver.integrationDriver( - responseDataCallback: (Map data) async { + responseDataCallback: (Map? data) async { final Map benchmarkLiveResult = - data['benchmarkLive'] as Map; + data?['benchmarkLive'] as Map; final Map fullyLiveResult = - data['fullyLive'] as Map; + data?['fullyLive'] as Map; if(benchmarkLiveResult['frame_count'] as int < 10 || fullyLiveResult['frame_count'] as int < 10) { diff --git a/dev/benchmarks/macrobenchmarks/test_driver/large_image_changer.dart b/dev/benchmarks/macrobenchmarks/test_driver/large_image_changer.dart index 0fed5f1f89..07d1aeaa96 100644 --- a/dev/benchmarks/macrobenchmarks/test_driver/large_image_changer.dart +++ b/dev/benchmarks/macrobenchmarks/test_driver/large_image_changer.dart @@ -11,7 +11,7 @@ import 'package:macrobenchmarks/common.dart'; import 'package:macrobenchmarks/main.dart'; Future main() async { - enableFlutterDriverExtension(handler: (String message) async { + enableFlutterDriverExtension(handler: (String? message) async { if (message == 'getTargetPlatform') { return defaultTargetPlatform.toString(); } diff --git a/dev/benchmarks/macrobenchmarks/test_driver/large_image_changer_test.dart b/dev/benchmarks/macrobenchmarks/test_driver/large_image_changer_test.dart index 8ac78c0596..b41445cf75 100644 --- a/dev/benchmarks/macrobenchmarks/test_driver/large_image_changer_test.dart +++ b/dev/benchmarks/macrobenchmarks/test_driver/large_image_changer_test.dart @@ -14,7 +14,7 @@ Future main() async { final String targetPlatform = await driver.requestData('getTargetPlatform'); - Timeline timeline; + Timeline? timeline; switch (targetPlatform) { case 'TargetPlatform.iOS': { diff --git a/dev/benchmarks/macrobenchmarks/test_driver/stack_size_perf_test.dart b/dev/benchmarks/macrobenchmarks/test_driver/stack_size_perf_test.dart index e47932c9d8..3989915694 100644 --- a/dev/benchmarks/macrobenchmarks/test_driver/stack_size_perf_test.dart +++ b/dev/benchmarks/macrobenchmarks/test_driver/stack_size_perf_test.dart @@ -16,7 +16,7 @@ const JsonEncoder _prettyEncoder = JsonEncoder.withIndent(' '); void main() { test('stack_size', () async { - int stackSizeInBytes; + late int stackSizeInBytes; await runDriverTestForRoute(kStackSizeRouteName, (FlutterDriver driver) async { final String stackSize = await driver.getText(find.byValueKey(kStackSizeKey)); expect(stackSize.isNotEmpty, isTrue); diff --git a/dev/benchmarks/macrobenchmarks/test_driver/util.dart b/dev/benchmarks/macrobenchmarks/test_driver/util.dart index e4bd50f0a0..5151609fc7 100644 --- a/dev/benchmarks/macrobenchmarks/test_driver/util.dart +++ b/dev/benchmarks/macrobenchmarks/test_driver/util.dart @@ -34,13 +34,13 @@ Future runDriverTestForRoute(String routeName, DriverTestCallBack body) as void macroPerfTest( String testName, String routeName, { - Duration pageDelay, + Duration? pageDelay, Duration duration = const Duration(seconds: 3), - Future Function(FlutterDriver driver) driverOps, - Future Function(FlutterDriver driver) setupOps, + Future Function(FlutterDriver driver)? driverOps, + Future Function(FlutterDriver driver)? setupOps, }) { test(testName, () async { - Timeline timeline; + late Timeline timeline; await runDriverTestForRoute(routeName, (FlutterDriver driver) async { if (pageDelay != null) { // Wait for the page to load @@ -48,7 +48,7 @@ void macroPerfTest( } if (setupOps != null) { - await setupOps(driver); + await setupOps(driver); } timeline = await driver.traceAction(() async { diff --git a/dev/benchmarks/macrobenchmarks/test_memory/heavy_gridview.dart b/dev/benchmarks/macrobenchmarks/test_memory/heavy_gridview.dart index cf3bf61df3..60a32c3880 100644 --- a/dev/benchmarks/macrobenchmarks/test_memory/heavy_gridview.dart +++ b/dev/benchmarks/macrobenchmarks/test_memory/heavy_gridview.dart @@ -10,8 +10,8 @@ import 'package:macrobenchmarks/main.dart'; Future endOfAnimation() async { do { - await SchedulerBinding.instance.endOfFrame; - } while (SchedulerBinding.instance.hasScheduledFrame); + await SchedulerBinding.instance!.endOfFrame; + } while (SchedulerBinding.instance!.hasScheduledFrame); } Future main() async { diff --git a/dev/benchmarks/macrobenchmarks/test_memory/large_images.dart b/dev/benchmarks/macrobenchmarks/test_memory/large_images.dart index 1b179227c9..9c004a9e9c 100644 --- a/dev/benchmarks/macrobenchmarks/test_memory/large_images.dart +++ b/dev/benchmarks/macrobenchmarks/test_memory/large_images.dart @@ -10,8 +10,8 @@ import 'package:macrobenchmarks/main.dart'; Future endOfAnimation() async { do { - await SchedulerBinding.instance.endOfFrame; - } while (SchedulerBinding.instance.hasScheduledFrame); + await SchedulerBinding.instance!.endOfFrame; + } while (SchedulerBinding.instance!.hasScheduledFrame); } Future main() async {