Provide more const constructors for keys. (#7907)

This commit is contained in:
Ian Hickson
2017-02-06 14:43:11 -08:00
committed by GitHub
parent 57ee52636b
commit e46f6e76b3

View File

@@ -30,7 +30,7 @@ abstract class Key {
/// Construct a [ValueKey<String>] with the given [String].
///
/// This is the simplest way to create keys.
factory Key(String value) => new ValueKey<String>(value);
const factory Key(String value) = ValueKey<String>;
/// Default constructor, used by subclasses.
///
@@ -154,7 +154,7 @@ abstract class GlobalKey<T extends State<StatefulWidget>> extends Key {
///
/// The label is purely for debugging and not used for comparing the identity
/// of the key.
factory GlobalKey({ String debugLabel }) => new LabeledGlobalKey<T>(debugLabel); // the label is purely for debugging purposes and is otherwise ignored
const factory GlobalKey({ String debugLabel }) = LabeledGlobalKey<T>._; // the label is purely for debugging purposes and is otherwise ignored
/// Creates a global key without a label.
///
@@ -302,6 +302,9 @@ class LabeledGlobalKey<T extends State<StatefulWidget>> extends GlobalKey<T> {
/// 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