Rationalise the Key API.

Add a way of having keys based on numeric types or DateTimes by having a ValueKey<T> class.
Remove the redundant ways of declaring things, except for leaving one shorthand -- you can say `new Key(s)` instead of `new ValueKey<String>(s)`.
This commit is contained in:
Hixie
2015-08-28 10:52:23 -07:00
parent 12e3897f40
commit 9047830c2e
14 changed files with 25 additions and 28 deletions

View File

@@ -30,7 +30,7 @@ abstract class FitnessItemRow extends Component {
FitnessItemRow({ FitnessItem item, this.onDismissed })
: this.item = item,
super(key: new Key(item.when.toString())) {
super(key: new ValueKey<DateTime>(item.when)) {
assert(onDismissed != null);
}

View File

@@ -142,7 +142,7 @@ class MineDiggerApp extends App {
new Row(
row,
justifyContent: FlexJustifyContent.center,
key: new Key.stringify(iy)
key: new ValueKey<int>(iy)
)
);
}

View File

@@ -13,7 +13,7 @@ class CardModel {
double height;
Color color;
String get label => "Item $value";
Key get key => new Key.fromObjectIdentity(this);
Key get key => new ObjectKey(this);
}
class CardCollectionApp extends App {

View File

@@ -12,7 +12,7 @@ class CardModel {
double height;
Color color;
String get label => "Card $value";
Key get key => new Key.fromObjectIdentity(this);
Key get key => new ObjectKey(this);
}
class EnsureVisibleApp extends App {

View File

@@ -15,7 +15,7 @@ class CardModel {
double height;
Color color;
String get label => "Card $value";
Key get key => new Key.fromObjectIdentity(this);
Key get key => new ObjectKey(this);
}
enum MarkerType { topLeft, bottomRight, touch }

View File

@@ -12,7 +12,7 @@ class CardModel {
Size size;
Color color;
String get label => "Card $value";
Key get key => new Key.fromObjectIdentity(this);
Key get key => new ObjectKey(this);
}
class PageableListApp extends App {

View File

@@ -35,7 +35,7 @@ class TabbedNavigatorApp extends App {
builder: () => _buildContent(text)
);
});
return _buildTabNavigator(n, views.toList(), const StringKey('textLabelsTabNavigator'));
return _buildTabNavigator(n, views.toList(), const ValueKey<String>('textLabelsTabNavigator'));
}
TabNavigator _buildIconLabelsTabNavigator(int n) {
@@ -46,7 +46,7 @@ class TabbedNavigatorApp extends App {
builder: () => _buildContent(icon_name)
);
});
return _buildTabNavigator(n, views.toList(), const StringKey('iconLabelsTabNavigator'));
return _buildTabNavigator(n, views.toList(), const ValueKey<String>('iconLabelsTabNavigator'));
}
TabNavigator _buildTextAndIconLabelsTabNavigator(int n) {
@@ -64,7 +64,7 @@ class TabbedNavigatorApp extends App {
builder: () => _buildContent("Summary")
)
];
return _buildTabNavigator(n, views, const StringKey('textAndIconLabelsTabNavigator'));
return _buildTabNavigator(n, views, const ValueKey<String>('textAndIconLabelsTabNavigator'));
}
TabNavigator _buildScrollableTabNavigator(int n) {
@@ -86,7 +86,7 @@ class TabbedNavigatorApp extends App {
builder: () => _buildContent(text)
);
});
return _buildTabNavigator(n, views.toList(), const StringKey('scrollableTabNavigator'), isScrollable: true);
return _buildTabNavigator(n, views.toList(), const ValueKey<String>('scrollableTabNavigator'), isScrollable: true);
}
@@ -118,7 +118,7 @@ class TabbedNavigatorApp extends App {
)
];
TabNavigator tabNavigator = _buildTabNavigator(4, views, const StringKey('tabs'));
TabNavigator tabNavigator = _buildTabNavigator(4, views, const ValueKey<String>('tabs'));
assert(selectedIndices.length == 5);
ToolBar toolbar = new ToolBar(