From e46f6e76b307883e119efdb8f68247796a3fad24 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 6 Feb 2017 14:43:11 -0800 Subject: [PATCH] Provide more const constructors for keys. (#7907) --- packages/flutter/lib/src/widgets/framework.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index bf77b16240..ff8b39ace5 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -30,7 +30,7 @@ abstract class Key { /// Construct a [ValueKey] with the given [String]. /// /// This is the simplest way to create keys. - factory Key(String value) => new ValueKey(value); + const factory Key(String value) = ValueKey; /// Default constructor, used by subclasses. /// @@ -154,7 +154,7 @@ abstract class GlobalKey> extends Key { /// /// The label is purely for debugging and not used for comparing the identity /// of the key. - factory GlobalKey({ String debugLabel }) => new LabeledGlobalKey(debugLabel); // the label is purely for debugging purposes and is otherwise ignored + const factory GlobalKey({ String debugLabel }) = LabeledGlobalKey._; // the label is purely for debugging purposes and is otherwise ignored /// Creates a global key without a label. /// @@ -302,6 +302,9 @@ class LabeledGlobalKey> extends GlobalKey { /// The label does not affect the key's identity. const LabeledGlobalKey(this._debugLabel) : super.constructor(); + // Used for forwarding the constructor from GlobalKey. + const LabeledGlobalKey._({ String debugLabel }) : _debugLabel = debugLabel, super.constructor(); + final String _debugLabel; @override