Commit 01b88ccc authored by Adam Barth's avatar Adam Barth

Merge pull request #710 from abarth/const_key

Key should be const
parents a2e75eae eb1b0333
...@@ -35,7 +35,7 @@ class TabbedNavigatorApp extends App { ...@@ -35,7 +35,7 @@ class TabbedNavigatorApp extends App {
builder: () => _buildContent(text) builder: () => _buildContent(text)
); );
}); });
return _buildTabNavigator(n, views.toList(), new Key('textLabelsTabNavigator')); return _buildTabNavigator(n, views.toList(), const StringKey('textLabelsTabNavigator'));
} }
TabNavigator _buildIconLabelsTabNavigator(int n) { TabNavigator _buildIconLabelsTabNavigator(int n) {
...@@ -46,7 +46,7 @@ class TabbedNavigatorApp extends App { ...@@ -46,7 +46,7 @@ class TabbedNavigatorApp extends App {
builder: () => _buildContent(icon_name) builder: () => _buildContent(icon_name)
); );
}); });
return _buildTabNavigator(n, views.toList(), new Key('iconLabelsTabNavigator')); return _buildTabNavigator(n, views.toList(), const StringKey('iconLabelsTabNavigator'));
} }
TabNavigator _buildTextAndIconLabelsTabNavigator(int n) { TabNavigator _buildTextAndIconLabelsTabNavigator(int n) {
...@@ -64,7 +64,7 @@ class TabbedNavigatorApp extends App { ...@@ -64,7 +64,7 @@ class TabbedNavigatorApp extends App {
builder: () => _buildContent("Summary") builder: () => _buildContent("Summary")
) )
]; ];
return _buildTabNavigator(n, views, new Key('textAndIconLabelsTabNavigator')); return _buildTabNavigator(n, views, const StringKey('textAndIconLabelsTabNavigator'));
} }
TabNavigator _buildScrollableTabNavigator(int n) { TabNavigator _buildScrollableTabNavigator(int n) {
...@@ -86,7 +86,7 @@ class TabbedNavigatorApp extends App { ...@@ -86,7 +86,7 @@ class TabbedNavigatorApp extends App {
builder: () => _buildContent(text) builder: () => _buildContent(text)
); );
}); });
return _buildTabNavigator(n, views.toList(), new Key('scrollableTabNavigator'), isScrollable: true); return _buildTabNavigator(n, views.toList(), const StringKey('scrollableTabNavigator'), isScrollable: true);
} }
...@@ -118,7 +118,7 @@ class TabbedNavigatorApp extends App { ...@@ -118,7 +118,7 @@ class TabbedNavigatorApp extends App {
) )
]; ];
TabNavigator tabNavigator = _buildTabNavigator(4, views, new Key('tabs')); TabNavigator tabNavigator = _buildTabNavigator(4, views, const StringKey('tabs'));
assert(selectedIndices.length == 5); assert(selectedIndices.length == 5);
ToolBar toolbar = new ToolBar( ToolBar toolbar = new ToolBar(
......
...@@ -8,6 +8,7 @@ import 'package:sky/mojo/keyboard.dart'; ...@@ -8,6 +8,7 @@ import 'package:sky/mojo/keyboard.dart';
import 'package:sky/painting/text_style.dart'; import 'package:sky/painting/text_style.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/focus.dart'; import 'package:sky/widgets/focus.dart';
import 'package:sky/widgets/framework.dart';
import 'package:sky/widgets/theme.dart'; import 'package:sky/widgets/theme.dart';
export 'package:sky/mojo/keyboard.dart' show KeyboardType_TEXT, KeyboardType_NUMBER, KeyboardType_PHONE, KeyboardType_DATETIME; export 'package:sky/mojo/keyboard.dart' show KeyboardType_TEXT, KeyboardType_NUMBER, KeyboardType_PHONE, KeyboardType_DATETIME;
...@@ -74,7 +75,7 @@ class Input extends StatefulComponent { ...@@ -74,7 +75,7 @@ class Input extends StatefulComponent {
if (placeholder != null && _value.isEmpty) { if (placeholder != null && _value.isEmpty) {
Widget child = new Opacity( Widget child = new Opacity(
key: new Key('placeholder'), key: const StringKey('placeholder'),
child: new Text(placeholder, style: textStyle), child: new Text(placeholder, style: textStyle),
opacity: themeData.hintOpacity opacity: themeData.hintOpacity
); );
......
...@@ -25,14 +25,14 @@ typedef Widget Builder(); ...@@ -25,14 +25,14 @@ typedef Widget Builder();
typedef void WidgetTreeWalker(Widget); typedef void WidgetTreeWalker(Widget);
abstract class Key { abstract class Key {
Key.constructor(); // so that subclasses can call us, since the Key() factory constructor shadows the implicit constructor const Key.constructor(); // so that subclasses can call us, since the Key() factory constructor shadows the implicit constructor
factory Key(String value) => new StringKey(value); factory Key(String value) => new StringKey(value);
factory Key.stringify(Object value) => new StringKey(value.toString()); factory Key.stringify(Object value) => new StringKey(value.toString());
factory Key.fromObjectIdentity(Object value) => new ObjectKey(value); factory Key.fromObjectIdentity(Object value) => new ObjectKey(value);
} }
class StringKey extends Key { class StringKey extends Key {
StringKey(this.value) : super.constructor(); const StringKey(this.value) : super.constructor();
final String value; final String value;
String toString() => '[\'${value}\']'; String toString() => '[\'${value}\']';
bool operator==(other) => other is StringKey && other.value == value; bool operator==(other) => other is StringKey && other.value == value;
...@@ -40,7 +40,7 @@ class StringKey extends Key { ...@@ -40,7 +40,7 @@ class StringKey extends Key {
} }
class ObjectKey extends Key { class ObjectKey extends Key {
ObjectKey(this.value) : super.constructor(); const ObjectKey(this.value) : super.constructor();
final Object value; final Object value;
String toString() => '[${value.runtimeType}(${value.hashCode})]'; String toString() => '[${value.runtimeType}(${value.hashCode})]';
bool operator==(other) => other is ObjectKey && identical(other.value, value); bool operator==(other) => other is ObjectKey && identical(other.value, value);
...@@ -50,7 +50,7 @@ class ObjectKey extends Key { ...@@ -50,7 +50,7 @@ class ObjectKey extends Key {
typedef void GlobalKeyRemovalListener(GlobalKey key); typedef void GlobalKeyRemovalListener(GlobalKey key);
abstract class GlobalKey extends Key { abstract class GlobalKey extends Key {
GlobalKey.constructor() : super.constructor(); // so that subclasses can call us, since the Key() factory constructor shadows the implicit constructor const GlobalKey.constructor() : super.constructor(); // so that subclasses can call us, since the Key() factory constructor shadows the implicit constructor
factory GlobalKey({ String label }) => new LabeledGlobalKey(label); factory GlobalKey({ String label }) => new LabeledGlobalKey(label);
factory GlobalKey.fromObjectIdentity(Object value) => new GlobalObjectKey(value); factory GlobalKey.fromObjectIdentity(Object value) => new GlobalObjectKey(value);
...@@ -136,13 +136,13 @@ abstract class GlobalKey extends Key { ...@@ -136,13 +136,13 @@ abstract class GlobalKey extends Key {
class LabeledGlobalKey extends GlobalKey { class LabeledGlobalKey extends GlobalKey {
// the label is purely for documentary purposes and does not affect the key // the label is purely for documentary purposes and does not affect the key
LabeledGlobalKey(this._label) : super.constructor(); const LabeledGlobalKey(this._label) : super.constructor();
final String _label; final String _label;
String toString() => '[GlobalKey ${_label != null ? _label : hashCode}]'; String toString() => '[GlobalKey ${_label != null ? _label : hashCode}]';
} }
class GlobalObjectKey extends GlobalKey { class GlobalObjectKey extends GlobalKey {
GlobalObjectKey(this.value) : super.constructor(); const GlobalObjectKey(this.value) : super.constructor();
final Object value; final Object value;
String toString() => '[GlobalKey ${value.runtimeType}(${value.hashCode})]'; String toString() => '[GlobalKey ${value.runtimeType}(${value.hashCode})]';
bool operator==(other) => other is GlobalObjectKey && identical(other.value, value); bool operator==(other) => other is GlobalObjectKey && identical(other.value, value);
......
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