From ea71bdca20fb7410544222a783bc0a03ccf6d6df Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 14 Apr 2017 10:38:58 -0700 Subject: [PATCH] Start using `@immutable` annotations (#9152) There are more places we can use this annotation, but this patch just gets us started. --- dev/benchmarks/microbenchmarks/pubspec.yaml | 2 +- dev/devicelab/pubspec.yaml | 2 +- packages/flutter/lib/foundation.dart | 1 + packages/flutter/lib/src/material/mergeable_material.dart | 4 ++-- packages/flutter/lib/src/painting/box_painter.dart | 6 ++++++ packages/flutter/lib/src/painting/colors.dart | 3 +++ packages/flutter/lib/src/painting/decoration.dart | 1 + packages/flutter/lib/src/painting/edge_insets.dart | 3 +++ packages/flutter/lib/src/painting/fractional_offset.dart | 3 +++ packages/flutter/lib/src/painting/text_span.dart | 1 + packages/flutter/lib/src/painting/text_style.dart | 3 +++ packages/flutter/lib/src/rendering/object.dart | 1 + packages/flutter/lib/src/rendering/sliver.dart | 1 + packages/flutter/lib/src/rendering/sliver_grid.dart | 2 ++ packages/flutter/lib/src/widgets/form.dart | 2 +- packages/flutter/lib/src/widgets/framework.dart | 1 + packages/flutter/lib/src/widgets/will_pop_scope.dart | 2 +- packages/flutter/pubspec.yaml | 2 +- packages/flutter/test/widgets/global_keys_moving_test.dart | 3 ++- packages/flutter_driver/pubspec.yaml | 2 +- packages/flutter_tools/pubspec.yaml | 2 +- 21 files changed, 37 insertions(+), 10 deletions(-) diff --git a/dev/benchmarks/microbenchmarks/pubspec.yaml b/dev/benchmarks/microbenchmarks/pubspec.yaml index 44fcf2abcf..52005fc574 100644 --- a/dev/benchmarks/microbenchmarks/pubspec.yaml +++ b/dev/benchmarks/microbenchmarks/pubspec.yaml @@ -1,7 +1,7 @@ name: microbenchmarks description: Small benchmarks for very specific parts of the Flutter framework. dependencies: - meta: ^1.0.3 + meta: ^1.0.5 flutter: sdk: flutter flutter_test: diff --git a/dev/devicelab/pubspec.yaml b/dev/devicelab/pubspec.yaml index 9d2aef1989..12815963c0 100644 --- a/dev/devicelab/pubspec.yaml +++ b/dev/devicelab/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: args: ^0.13.4 - meta: ^1.0.4 + meta: ^1.0.5 path: ^1.4.0 process: 2.0.3 stack_trace: ^1.4.0 diff --git a/packages/flutter/lib/foundation.dart b/packages/flutter/lib/foundation.dart index e21c0ae319..6221f086f6 100644 --- a/packages/flutter/lib/foundation.dart +++ b/packages/flutter/lib/foundation.dart @@ -10,6 +10,7 @@ library foundation; export 'package:meta/meta.dart' show + immutable, mustCallSuper, optionalTypeArgs, protected, diff --git a/packages/flutter/lib/src/material/mergeable_material.dart b/packages/flutter/lib/src/material/mergeable_material.dart index 7c6cea02b1..205ceebec6 100644 --- a/packages/flutter/lib/src/material/mergeable_material.dart +++ b/packages/flutter/lib/src/material/mergeable_material.dart @@ -643,8 +643,8 @@ class _MergeableMaterialListBody extends ListBody { this.boxShadows }) : super(children: children, mainAxis: mainAxis); - List items; - List boxShadows; + final List items; + final List boxShadows; @override RenderListBody createRenderObject(BuildContext context) { diff --git a/packages/flutter/lib/src/painting/box_painter.dart b/packages/flutter/lib/src/painting/box_painter.dart index ff9089d1d2..b9ccc110ee 100644 --- a/packages/flutter/lib/src/painting/box_painter.dart +++ b/packages/flutter/lib/src/painting/box_painter.dart @@ -33,6 +33,7 @@ enum BoxShape { /// An immutable set of radii for each corner of a rectangle. /// /// Used by [BoxDecoration] when the shape is a [BoxShape.rectangle]. +@immutable class BorderRadius { /// Creates a border radius where all radii are [radius]. const BorderRadius.all(Radius radius) : this.only( @@ -151,6 +152,7 @@ enum BorderStyle { } /// A side of a border of a box. +@immutable class BorderSide { /// Creates the side of a border. /// @@ -250,6 +252,7 @@ class BorderSide { } /// A border of a box, comprised of four sides. +@immutable class Border { /// Creates a border. /// @@ -502,6 +505,7 @@ class Border { /// (e.g., has a border radius or a circular shape). /// /// This class is similar to CSS box-shadow. +@immutable class BoxShadow { /// Creates a box shadow. /// @@ -611,6 +615,7 @@ class BoxShadow { } /// A 2D gradient. +@immutable abstract class Gradient { /// Abstract const constructor. This constructor enables subclasses to provide /// const constructors so that they can be used in const expressions. @@ -963,6 +968,7 @@ void paintImage({ /// /// The image is painted using [paintImage], which describes the meanings of the /// various fields on this class in more detail. +@immutable class BackgroundImage { /// Creates a background image. /// diff --git a/packages/flutter/lib/src/painting/colors.dart b/packages/flutter/lib/src/painting/colors.dart index 20b3c87a74..5d0bfdad7c 100644 --- a/packages/flutter/lib/src/painting/colors.dart +++ b/packages/flutter/lib/src/painting/colors.dart @@ -4,11 +4,14 @@ import 'dart:ui' show Color, lerpDouble, hashValues; +import 'package:flutter/foundation.dart'; + /// A color represented using [alpha], [hue], [saturation], and [value]. /// /// An [HSVColor] is represented in a parameter space that's motivated by human /// perception. The representation is useful for some color computations (e.g., /// rotating the hue through the colors of the rainbow). +@immutable class HSVColor { /// Creates a color. /// diff --git a/packages/flutter/lib/src/painting/decoration.dart b/packages/flutter/lib/src/painting/decoration.dart index 9f9f714e56..95d55a0717 100644 --- a/packages/flutter/lib/src/painting/decoration.dart +++ b/packages/flutter/lib/src/painting/decoration.dart @@ -24,6 +24,7 @@ export 'edge_insets.dart' show EdgeInsets; /// method to obtain a [BoxPainter]. [Decoration] objects can be /// shared between boxes; [BoxPainter] objects can cache resources to /// make painting on a particular surface faster. +@immutable abstract class Decoration { /// Abstract const constructor. This constructor enables subclasses to provide /// const constructors so that they can be used in const expressions. diff --git a/packages/flutter/lib/src/painting/edge_insets.dart b/packages/flutter/lib/src/painting/edge_insets.dart index 2bea989035..0beff5b695 100644 --- a/packages/flutter/lib/src/painting/edge_insets.dart +++ b/packages/flutter/lib/src/painting/edge_insets.dart @@ -4,6 +4,8 @@ import 'dart:ui' as ui show lerpDouble, WindowPadding; +import 'package:flutter/foundation.dart'; + import 'basic_types.dart'; /// The two cardinal directions in two dimensions. @@ -19,6 +21,7 @@ enum Axis { /// /// Typically used for an offset from each of the four sides of a box. For /// example, the padding inside a box can be represented using this class. +@immutable class EdgeInsets { /// Creates insets from offsets from the left, top, right, and bottom. const EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom); diff --git a/packages/flutter/lib/src/painting/fractional_offset.dart b/packages/flutter/lib/src/painting/fractional_offset.dart index 7d05a8d9b1..2529da1a5a 100644 --- a/packages/flutter/lib/src/painting/fractional_offset.dart +++ b/packages/flutter/lib/src/painting/fractional_offset.dart @@ -4,12 +4,15 @@ import 'dart:ui' as ui show lerpDouble; +import 'package:flutter/foundation.dart'; + import 'basic_types.dart'; /// An offset that's expressed as a fraction of a Size. /// /// FractionalOffset(1.0, 0.0) represents the top right of the Size, /// FractionalOffset(0.0, 1.0) represents the bottom left of the Size, +@immutable class FractionalOffset { /// Creates a fractional offset. /// diff --git a/packages/flutter/lib/src/painting/text_span.dart b/packages/flutter/lib/src/painting/text_span.dart index 95aa0ed3fa..0b5f824d63 100644 --- a/packages/flutter/lib/src/painting/text_span.dart +++ b/packages/flutter/lib/src/painting/text_span.dart @@ -45,6 +45,7 @@ bool _deepEquals(List a, List b) { /// * [Text] /// * [RichText] /// * [TextPainter] +@immutable class TextSpan { /// Creates a [TextSpan] with the given values. /// diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index b2d8d98c58..5083b01b2a 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -4,9 +4,12 @@ import 'dart:ui' as ui show ParagraphStyle, TextStyle, lerpDouble; +import 'package:flutter/foundation.dart'; + import 'basic_types.dart'; /// An immutable style in which paint text. +@immutable class TextStyle { /// Creates a text style. const TextStyle({ diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index 5a9f342380..3db759a676 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -520,6 +520,7 @@ class PaintingContext { /// /// * The [toString] method, which should describe the constraints so that they /// appear in a usefully readable form in the output of [debugDumpRenderTree]. +@immutable abstract class Constraints { /// Abstract const constructor. This constructor enables subclasses to provide /// const constructors so that they can be used in const expressions. diff --git a/packages/flutter/lib/src/rendering/sliver.dart b/packages/flutter/lib/src/rendering/sliver.dart index e77926acd8..c8940ed885 100644 --- a/packages/flutter/lib/src/rendering/sliver.dart +++ b/packages/flutter/lib/src/rendering/sliver.dart @@ -422,6 +422,7 @@ class SliverConstraints extends Constraints { /// /// A sliver can occupy space in several different ways, which is why this class /// contains multiple values. +@immutable class SliverGeometry { /// Creates an object that describes the amount of space occupied by a sliver. /// diff --git a/packages/flutter/lib/src/rendering/sliver_grid.dart b/packages/flutter/lib/src/rendering/sliver_grid.dart index d4c0840622..26110daa39 100644 --- a/packages/flutter/lib/src/rendering/sliver_grid.dart +++ b/packages/flutter/lib/src/rendering/sliver_grid.dart @@ -21,6 +21,7 @@ import 'sliver_multi_box_adaptor.dart'; /// to describe the child's placement. /// * [RenderSliverGrid], which uses this class during its /// [RenderSliverGrid.performLayout] method. +@immutable class SliverGridGeometry { /// Creates an object that describes the placement of a child in a [RenderSliverGrid]. const SliverGridGeometry({ @@ -99,6 +100,7 @@ class SliverGridGeometry { /// delegates's layout. /// * [RenderSliverGrid], which uses this class during its /// [RenderSliverGrid.performLayout] method. +@immutable abstract class SliverGridLayout { /// Abstract const constructor. This constructor enables subclasses to provide /// const constructors so that they can be used in const expressions. diff --git a/packages/flutter/lib/src/widgets/form.dart b/packages/flutter/lib/src/widgets/form.dart index 6df0a30825..589e2769e3 100644 --- a/packages/flutter/lib/src/widgets/form.dart +++ b/packages/flutter/lib/src/widgets/form.dart @@ -56,7 +56,7 @@ class Form extends StatefulWidget { /// /// If the callback returns a Future that resolves to false, the form's route /// will not be popped. - WillPopCallback onWillPop; + final WillPopCallback onWillPop; @override FormState createState() => new FormState(); diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 3502c8dfbe..d26387394c 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -391,6 +391,7 @@ class TypeMatcher { /// be read by descendant widgets. /// * [StatelessWidget], for widgets that always build the same way given a /// particular configuration and ambient state. +@immutable abstract class Widget { /// Initializes [key] for subclasses. const Widget({ this.key }); diff --git a/packages/flutter/lib/src/widgets/will_pop_scope.dart b/packages/flutter/lib/src/widgets/will_pop_scope.dart index 62ebb2ba6b..8acd574ecf 100644 --- a/packages/flutter/lib/src/widgets/will_pop_scope.dart +++ b/packages/flutter/lib/src/widgets/will_pop_scope.dart @@ -34,7 +34,7 @@ class WillPopScope extends StatefulWidget { /// /// If the callback returns a Future that resolves to false, the enclosing /// route will not be popped. - WillPopCallback onWillPop; + final WillPopCallback onWillPop; @override _WillPopScopeState createState() => new _WillPopScopeState(); diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index d17efa656d..73efec3251 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -8,7 +8,7 @@ dependencies: collection: '>=1.9.1 <2.0.0' http: '>=0.11.3+12' intl: '>=0.14.0 <0.15.0' - meta: ^1.0.4 + meta: ^1.0.5 typed_data: ^1.1.3 vector_math: '>=2.0.3 <3.0.0' diff --git a/packages/flutter/test/widgets/global_keys_moving_test.dart b/packages/flutter/test/widgets/global_keys_moving_test.dart index 393344ba32..b5ad55f9fe 100644 --- a/packages/flutter/test/widgets/global_keys_moving_test.dart +++ b/packages/flutter/test/widgets/global_keys_moving_test.dart @@ -31,7 +31,8 @@ class StatefulLeafState extends State { class KeyedWrapper extends StatelessWidget { KeyedWrapper(this.key1, this.key2); - Key key1, key2; + final Key key1; + final Key key2; @override Widget build(BuildContext context) { diff --git a/packages/flutter_driver/pubspec.yaml b/packages/flutter_driver/pubspec.yaml index e5ff53c529..384771916a 100644 --- a/packages/flutter_driver/pubspec.yaml +++ b/packages/flutter_driver/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: file: 2.3.2 json_rpc_2: '^2.0.0' matcher: '>=0.12.0 <1.0.0' - meta: ^1.0.4 + meta: ^1.0.5 path: '^1.4.0' web_socket_channel: '^1.0.0' vm_service_client: '0.2.2+4' diff --git a/packages/flutter_tools/pubspec.yaml b/packages/flutter_tools/pubspec.yaml index 7a2e085e89..2bb843f7c8 100644 --- a/packages/flutter_tools/pubspec.yaml +++ b/packages/flutter_tools/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: json_rpc_2: ^2.0.0 json_schema: 1.0.6 linter: 0.1.30 - meta: ^1.0.4 + meta: ^1.0.5 mustache: ^0.2.5 package_config: '>=0.1.5 <2.0.0' platform: 2.0.0