Commit ea71bdca authored by Adam Barth's avatar Adam Barth Committed by GitHub

Start using `@immutable` annotations (#9152)

There are more places we can use this annotation, but this patch just gets us
started.
parent 70536223
name: microbenchmarks name: microbenchmarks
description: Small benchmarks for very specific parts of the Flutter framework. description: Small benchmarks for very specific parts of the Flutter framework.
dependencies: dependencies:
meta: ^1.0.3 meta: ^1.0.5
flutter: flutter:
sdk: flutter sdk: flutter
flutter_test: flutter_test:
......
...@@ -9,7 +9,7 @@ environment: ...@@ -9,7 +9,7 @@ environment:
dependencies: dependencies:
args: ^0.13.4 args: ^0.13.4
meta: ^1.0.4 meta: ^1.0.5
path: ^1.4.0 path: ^1.4.0
process: 2.0.3 process: 2.0.3
stack_trace: ^1.4.0 stack_trace: ^1.4.0
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
library foundation; library foundation;
export 'package:meta/meta.dart' show export 'package:meta/meta.dart' show
immutable,
mustCallSuper, mustCallSuper,
optionalTypeArgs, optionalTypeArgs,
protected, protected,
......
...@@ -643,8 +643,8 @@ class _MergeableMaterialListBody extends ListBody { ...@@ -643,8 +643,8 @@ class _MergeableMaterialListBody extends ListBody {
this.boxShadows this.boxShadows
}) : super(children: children, mainAxis: mainAxis); }) : super(children: children, mainAxis: mainAxis);
List<MergeableMaterialItem> items; final List<MergeableMaterialItem> items;
List<BoxShadow> boxShadows; final List<BoxShadow> boxShadows;
@override @override
RenderListBody createRenderObject(BuildContext context) { RenderListBody createRenderObject(BuildContext context) {
......
...@@ -33,6 +33,7 @@ enum BoxShape { ...@@ -33,6 +33,7 @@ enum BoxShape {
/// An immutable set of radii for each corner of a rectangle. /// An immutable set of radii for each corner of a rectangle.
/// ///
/// Used by [BoxDecoration] when the shape is a [BoxShape.rectangle]. /// Used by [BoxDecoration] when the shape is a [BoxShape.rectangle].
@immutable
class BorderRadius { class BorderRadius {
/// Creates a border radius where all radii are [radius]. /// Creates a border radius where all radii are [radius].
const BorderRadius.all(Radius radius) : this.only( const BorderRadius.all(Radius radius) : this.only(
...@@ -151,6 +152,7 @@ enum BorderStyle { ...@@ -151,6 +152,7 @@ enum BorderStyle {
} }
/// A side of a border of a box. /// A side of a border of a box.
@immutable
class BorderSide { class BorderSide {
/// Creates the side of a border. /// Creates the side of a border.
/// ///
...@@ -250,6 +252,7 @@ class BorderSide { ...@@ -250,6 +252,7 @@ class BorderSide {
} }
/// A border of a box, comprised of four sides. /// A border of a box, comprised of four sides.
@immutable
class Border { class Border {
/// Creates a border. /// Creates a border.
/// ///
...@@ -502,6 +505,7 @@ class Border { ...@@ -502,6 +505,7 @@ class Border {
/// (e.g., has a border radius or a circular shape). /// (e.g., has a border radius or a circular shape).
/// ///
/// This class is similar to CSS box-shadow. /// This class is similar to CSS box-shadow.
@immutable
class BoxShadow { class BoxShadow {
/// Creates a box shadow. /// Creates a box shadow.
/// ///
...@@ -611,6 +615,7 @@ class BoxShadow { ...@@ -611,6 +615,7 @@ class BoxShadow {
} }
/// A 2D gradient. /// A 2D gradient.
@immutable
abstract class Gradient { abstract class Gradient {
/// Abstract const constructor. This constructor enables subclasses to provide /// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions. /// const constructors so that they can be used in const expressions.
...@@ -963,6 +968,7 @@ void paintImage({ ...@@ -963,6 +968,7 @@ void paintImage({
/// ///
/// The image is painted using [paintImage], which describes the meanings of the /// The image is painted using [paintImage], which describes the meanings of the
/// various fields on this class in more detail. /// various fields on this class in more detail.
@immutable
class BackgroundImage { class BackgroundImage {
/// Creates a background image. /// Creates a background image.
/// ///
......
...@@ -4,11 +4,14 @@ ...@@ -4,11 +4,14 @@
import 'dart:ui' show Color, lerpDouble, hashValues; import 'dart:ui' show Color, lerpDouble, hashValues;
import 'package:flutter/foundation.dart';
/// A color represented using [alpha], [hue], [saturation], and [value]. /// A color represented using [alpha], [hue], [saturation], and [value].
/// ///
/// An [HSVColor] is represented in a parameter space that's motivated by human /// An [HSVColor] is represented in a parameter space that's motivated by human
/// perception. The representation is useful for some color computations (e.g., /// perception. The representation is useful for some color computations (e.g.,
/// rotating the hue through the colors of the rainbow). /// rotating the hue through the colors of the rainbow).
@immutable
class HSVColor { class HSVColor {
/// Creates a color. /// Creates a color.
/// ///
......
...@@ -24,6 +24,7 @@ export 'edge_insets.dart' show EdgeInsets; ...@@ -24,6 +24,7 @@ export 'edge_insets.dart' show EdgeInsets;
/// method to obtain a [BoxPainter]. [Decoration] objects can be /// method to obtain a [BoxPainter]. [Decoration] objects can be
/// shared between boxes; [BoxPainter] objects can cache resources to /// shared between boxes; [BoxPainter] objects can cache resources to
/// make painting on a particular surface faster. /// make painting on a particular surface faster.
@immutable
abstract class Decoration { abstract class Decoration {
/// Abstract const constructor. This constructor enables subclasses to provide /// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions. /// const constructors so that they can be used in const expressions.
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
import 'dart:ui' as ui show lerpDouble, WindowPadding; import 'dart:ui' as ui show lerpDouble, WindowPadding;
import 'package:flutter/foundation.dart';
import 'basic_types.dart'; import 'basic_types.dart';
/// The two cardinal directions in two dimensions. /// The two cardinal directions in two dimensions.
...@@ -19,6 +21,7 @@ enum Axis { ...@@ -19,6 +21,7 @@ enum Axis {
/// ///
/// Typically used for an offset from each of the four sides of a box. For /// 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. /// example, the padding inside a box can be represented using this class.
@immutable
class EdgeInsets { class EdgeInsets {
/// Creates insets from offsets from the left, top, right, and bottom. /// Creates insets from offsets from the left, top, right, and bottom.
const EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom); const EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom);
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
import 'dart:ui' as ui show lerpDouble; import 'dart:ui' as ui show lerpDouble;
import 'package:flutter/foundation.dart';
import 'basic_types.dart'; import 'basic_types.dart';
/// An offset that's expressed as a fraction of a Size. /// An offset that's expressed as a fraction of a Size.
/// ///
/// FractionalOffset(1.0, 0.0) represents the top right of the 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, /// FractionalOffset(0.0, 1.0) represents the bottom left of the Size,
@immutable
class FractionalOffset { class FractionalOffset {
/// Creates a fractional offset. /// Creates a fractional offset.
/// ///
......
...@@ -45,6 +45,7 @@ bool _deepEquals(List<Object> a, List<Object> b) { ...@@ -45,6 +45,7 @@ bool _deepEquals(List<Object> a, List<Object> b) {
/// * [Text] /// * [Text]
/// * [RichText] /// * [RichText]
/// * [TextPainter] /// * [TextPainter]
@immutable
class TextSpan { class TextSpan {
/// Creates a [TextSpan] with the given values. /// Creates a [TextSpan] with the given values.
/// ///
......
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
import 'dart:ui' as ui show ParagraphStyle, TextStyle, lerpDouble; import 'dart:ui' as ui show ParagraphStyle, TextStyle, lerpDouble;
import 'package:flutter/foundation.dart';
import 'basic_types.dart'; import 'basic_types.dart';
/// An immutable style in which paint text. /// An immutable style in which paint text.
@immutable
class TextStyle { class TextStyle {
/// Creates a text style. /// Creates a text style.
const TextStyle({ const TextStyle({
......
...@@ -520,6 +520,7 @@ class PaintingContext { ...@@ -520,6 +520,7 @@ class PaintingContext {
/// ///
/// * The [toString] method, which should describe the constraints so that they /// * The [toString] method, which should describe the constraints so that they
/// appear in a usefully readable form in the output of [debugDumpRenderTree]. /// appear in a usefully readable form in the output of [debugDumpRenderTree].
@immutable
abstract class Constraints { abstract class Constraints {
/// Abstract const constructor. This constructor enables subclasses to provide /// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions. /// const constructors so that they can be used in const expressions.
......
...@@ -422,6 +422,7 @@ class SliverConstraints extends Constraints { ...@@ -422,6 +422,7 @@ class SliverConstraints extends Constraints {
/// ///
/// A sliver can occupy space in several different ways, which is why this class /// A sliver can occupy space in several different ways, which is why this class
/// contains multiple values. /// contains multiple values.
@immutable
class SliverGeometry { class SliverGeometry {
/// Creates an object that describes the amount of space occupied by a sliver. /// Creates an object that describes the amount of space occupied by a sliver.
/// ///
......
...@@ -21,6 +21,7 @@ import 'sliver_multi_box_adaptor.dart'; ...@@ -21,6 +21,7 @@ import 'sliver_multi_box_adaptor.dart';
/// to describe the child's placement. /// to describe the child's placement.
/// * [RenderSliverGrid], which uses this class during its /// * [RenderSliverGrid], which uses this class during its
/// [RenderSliverGrid.performLayout] method. /// [RenderSliverGrid.performLayout] method.
@immutable
class SliverGridGeometry { class SliverGridGeometry {
/// Creates an object that describes the placement of a child in a [RenderSliverGrid]. /// Creates an object that describes the placement of a child in a [RenderSliverGrid].
const SliverGridGeometry({ const SliverGridGeometry({
...@@ -99,6 +100,7 @@ class SliverGridGeometry { ...@@ -99,6 +100,7 @@ class SliverGridGeometry {
/// delegates's layout. /// delegates's layout.
/// * [RenderSliverGrid], which uses this class during its /// * [RenderSliverGrid], which uses this class during its
/// [RenderSliverGrid.performLayout] method. /// [RenderSliverGrid.performLayout] method.
@immutable
abstract class SliverGridLayout { abstract class SliverGridLayout {
/// Abstract const constructor. This constructor enables subclasses to provide /// Abstract const constructor. This constructor enables subclasses to provide
/// const constructors so that they can be used in const expressions. /// const constructors so that they can be used in const expressions.
......
...@@ -56,7 +56,7 @@ class Form extends StatefulWidget { ...@@ -56,7 +56,7 @@ class Form extends StatefulWidget {
/// ///
/// If the callback returns a Future that resolves to false, the form's route /// If the callback returns a Future that resolves to false, the form's route
/// will not be popped. /// will not be popped.
WillPopCallback onWillPop; final WillPopCallback onWillPop;
@override @override
FormState createState() => new FormState(); FormState createState() => new FormState();
......
...@@ -391,6 +391,7 @@ class TypeMatcher<T> { ...@@ -391,6 +391,7 @@ class TypeMatcher<T> {
/// be read by descendant widgets. /// be read by descendant widgets.
/// * [StatelessWidget], for widgets that always build the same way given a /// * [StatelessWidget], for widgets that always build the same way given a
/// particular configuration and ambient state. /// particular configuration and ambient state.
@immutable
abstract class Widget { abstract class Widget {
/// Initializes [key] for subclasses. /// Initializes [key] for subclasses.
const Widget({ this.key }); const Widget({ this.key });
......
...@@ -34,7 +34,7 @@ class WillPopScope extends StatefulWidget { ...@@ -34,7 +34,7 @@ class WillPopScope extends StatefulWidget {
/// ///
/// If the callback returns a Future that resolves to false, the enclosing /// If the callback returns a Future that resolves to false, the enclosing
/// route will not be popped. /// route will not be popped.
WillPopCallback onWillPop; final WillPopCallback onWillPop;
@override @override
_WillPopScopeState createState() => new _WillPopScopeState(); _WillPopScopeState createState() => new _WillPopScopeState();
......
...@@ -8,7 +8,7 @@ dependencies: ...@@ -8,7 +8,7 @@ dependencies:
collection: '>=1.9.1 <2.0.0' collection: '>=1.9.1 <2.0.0'
http: '>=0.11.3+12' http: '>=0.11.3+12'
intl: '>=0.14.0 <0.15.0' intl: '>=0.14.0 <0.15.0'
meta: ^1.0.4 meta: ^1.0.5
typed_data: ^1.1.3 typed_data: ^1.1.3
vector_math: '>=2.0.3 <3.0.0' vector_math: '>=2.0.3 <3.0.0'
......
...@@ -31,7 +31,8 @@ class StatefulLeafState extends State<StatefulLeaf> { ...@@ -31,7 +31,8 @@ class StatefulLeafState extends State<StatefulLeaf> {
class KeyedWrapper extends StatelessWidget { class KeyedWrapper extends StatelessWidget {
KeyedWrapper(this.key1, this.key2); KeyedWrapper(this.key1, this.key2);
Key key1, key2; final Key key1;
final Key key2;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -11,7 +11,7 @@ dependencies: ...@@ -11,7 +11,7 @@ dependencies:
file: 2.3.2 file: 2.3.2
json_rpc_2: '^2.0.0' json_rpc_2: '^2.0.0'
matcher: '>=0.12.0 <1.0.0' matcher: '>=0.12.0 <1.0.0'
meta: ^1.0.4 meta: ^1.0.5
path: '^1.4.0' path: '^1.4.0'
web_socket_channel: '^1.0.0' web_socket_channel: '^1.0.0'
vm_service_client: '0.2.2+4' vm_service_client: '0.2.2+4'
......
...@@ -19,7 +19,7 @@ dependencies: ...@@ -19,7 +19,7 @@ dependencies:
json_rpc_2: ^2.0.0 json_rpc_2: ^2.0.0
json_schema: 1.0.6 json_schema: 1.0.6
linter: 0.1.30 linter: 0.1.30
meta: ^1.0.4 meta: ^1.0.5
mustache: ^0.2.5 mustache: ^0.2.5
package_config: '>=0.1.5 <2.0.0' package_config: '>=0.1.5 <2.0.0'
platform: 2.0.0 platform: 2.0.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment