From de717bafe9d3c5c25d5fed04ecb8822eaf3dbd52 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 14:38:44 -0700 Subject: [PATCH 01/22] Images don't appears in VariableHeightScrollables When we build widgets during layout we weren't notifying those widgets that they were mounted. Now we notify mount status changes when exiting build phases inside layout. Fixes #176 --- .../widgets/variable_height_scrollable.dart | 2 ++ packages/flutter/lib/widgets/widget.dart | 20 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/flutter/lib/widgets/variable_height_scrollable.dart b/packages/flutter/lib/widgets/variable_height_scrollable.dart index 7799d913b2..66f060f85d 100644 --- a/packages/flutter/lib/widgets/variable_height_scrollable.dart +++ b/packages/flutter/lib/widgets/variable_height_scrollable.dart @@ -8,6 +8,8 @@ import 'package:sky/widgets/block_viewport.dart'; import 'package:sky/widgets/scrollable.dart'; import 'package:sky/widgets/widget.dart'; +export 'package:sky/widgets/block_viewport.dart' show BlockViewportLayoutState; + class VariableHeightScrollable extends Scrollable { VariableHeightScrollable({ String key, diff --git a/packages/flutter/lib/widgets/widget.dart b/packages/flutter/lib/widgets/widget.dart index 637f39084f..6f96239056 100644 --- a/packages/flutter/lib/widgets/widget.dart +++ b/packages/flutter/lib/widgets/widget.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'dart:collection'; import 'dart:sky' as sky; -import 'package:sky/base/debug.dart'; import 'package:sky/base/hit_test.dart'; import 'package:sky/mojo/activity.dart' as activity; import 'package:sky/rendering/box.dart'; @@ -600,17 +599,20 @@ int _inLayoutCallbackBuilder = 0; class LayoutCallbackBuilderHandle { bool _active = true; } LayoutCallbackBuilderHandle enterLayoutCallbackBuilder() { - if (!inDebugBuild) - return null; - _inLayoutCallbackBuilder += 1; + assert(() { + _inLayoutCallbackBuilder += 1; + return true; + }); return new LayoutCallbackBuilderHandle(); } void exitLayoutCallbackBuilder(LayoutCallbackBuilderHandle handle) { - if (!inDebugBuild) - return; - assert(handle._active); - handle._active = false; - _inLayoutCallbackBuilder -= 1; + assert(() { + assert(handle._active); + handle._active = false; + _inLayoutCallbackBuilder -= 1; + return true; + }); + Widget._notifyMountStatusChanged(); } List _debugFrameTimes = []; From ed82572205507d758767750f9372faeeb84b8314 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 14:56:54 -0700 Subject: [PATCH 02/22] Roll version to 20 --- packages/flutter/CHANGELOG.md | 4 ++++ .../flutter/example/demo_launcher/apk/AndroidManifest.xml | 2 +- .../example/demo_launcher/apk/release_notes/0.0.20.txt | 1 + packages/flutter/pubspec.yaml | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 packages/flutter/example/demo_launcher/apk/release_notes/0.0.20.txt diff --git a/packages/flutter/CHANGELOG.md b/packages/flutter/CHANGELOG.md index 448e203418..7dd98e6c8a 100644 --- a/packages/flutter/CHANGELOG.md +++ b/packages/flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.20 + + - 167 changes: https://github.com/domokit/mojo/compare/f2830c7...603f589 + ## 0.0.19 - 49 changes: https://github.com/domokit/mojo/compare/a64559a...1b8968c diff --git a/packages/flutter/example/demo_launcher/apk/AndroidManifest.xml b/packages/flutter/example/demo_launcher/apk/AndroidManifest.xml index a10f9ce99f..dc14953b95 100644 --- a/packages/flutter/example/demo_launcher/apk/AndroidManifest.xml +++ b/packages/flutter/example/demo_launcher/apk/AndroidManifest.xml @@ -3,7 +3,7 @@ Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> - + diff --git a/packages/flutter/example/demo_launcher/apk/release_notes/0.0.20.txt b/packages/flutter/example/demo_launcher/apk/release_notes/0.0.20.txt new file mode 100644 index 0000000000..1deb9ce393 --- /dev/null +++ b/packages/flutter/example/demo_launcher/apk/release_notes/0.0.20.txt @@ -0,0 +1 @@ +Fixes crash on Nexus 6 diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index 89af220a4e..7ef9c6b855 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -11,4 +11,4 @@ environment: sdk: '>=1.8.0 <2.0.0' homepage: https://github.com/domokit/mojo/tree/master/sky name: sky -version: 0.0.19 +version: 0.0.20 From 9da399b0e15dcaeb755783b681a7aca9fa2805d0 Mon Sep 17 00:00:00 2001 From: Hixie Date: Tue, 21 Jul 2015 14:54:03 -0700 Subject: [PATCH 03/22] Rationalise usage of keys in navigator.dart. Route (named routes) no longer have a key, and have their own storage for their names. RouseState no longer has a key, and uses an owner field pointing to a StatefulComponent instead. As such, RouteBase no longer has a key. HistoryEntry no longer uses a global int to ensure uniqueness. Propagated this to stocks app. --- .../example/stocks/lib/stock_home.dart | 3 ++- .../example/stocks/lib/stock_settings.dart | 2 +- packages/flutter/lib/widgets/drawer.dart | 3 ++- packages/flutter/lib/widgets/navigator.dart | 25 ++++++++----------- packages/flutter/lib/widgets/popup_menu.dart | 5 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/flutter/example/stocks/lib/stock_home.dart b/packages/flutter/example/stocks/lib/stock_home.dart index b7a8b89026..4ce3187ad6 100644 --- a/packages/flutter/example/stocks/lib/stock_home.dart +++ b/packages/flutter/example/stocks/lib/stock_home.dart @@ -69,7 +69,8 @@ class StockHome extends AnimatedComponent { } void _handleSearchEnd() { - assert(navigator.currentRoute.key == this); + assert(navigator.currentRoute is RouteState); + assert((navigator.currentRoute as RouteState).owner == this); // TODO(ianh): remove cast once analyzer is cleverer navigator.pop(); setState(() { _isSearching = false; diff --git a/packages/flutter/example/stocks/lib/stock_settings.dart b/packages/flutter/example/stocks/lib/stock_settings.dart index a49047c833..76e5c0389e 100644 --- a/packages/flutter/example/stocks/lib/stock_settings.dart +++ b/packages/flutter/example/stocks/lib/stock_settings.dart @@ -61,7 +61,7 @@ class StockSettings extends StatefulComponent { break; case StockMode.pessimistic: showModeDialog = true; - navigator.pushState("/settings/confirm", (_) { + navigator.pushState(this, (_) { showModeDialog = false; }); break; diff --git a/packages/flutter/lib/widgets/drawer.dart b/packages/flutter/lib/widgets/drawer.dart index 781970ea1d..b45aa9f191 100644 --- a/packages/flutter/lib/widgets/drawer.dart +++ b/packages/flutter/lib/widgets/drawer.dart @@ -143,7 +143,8 @@ class Drawer extends AnimatedComponent { if (_lastStatus != null && status != _lastStatus) { if (status == DrawerStatus.inactive && navigator != null && - navigator.currentRoute.key == this) + navigator.currentRoute is RouteState && + (navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer navigator.pop(); if (onStatusChanged != null) onStatusChanged(status); diff --git a/packages/flutter/lib/widgets/navigator.dart b/packages/flutter/lib/widgets/navigator.dart index 8254bbef58..1a20b5aeb4 100644 --- a/packages/flutter/lib/widgets/navigator.dart +++ b/packages/flutter/lib/widgets/navigator.dart @@ -12,25 +12,24 @@ import 'package:vector_math/vector_math.dart'; typedef Widget Builder(Navigator navigator, RouteBase route); abstract class RouteBase { - RouteBase({ this.key }); - final Object key; Widget build(Navigator navigator, RouteBase route); void popState() { } } class Route extends RouteBase { - Route({ String name, this.builder }) : super(key: name); - String get name => key; + Route({ this.name, this.builder }); + final String name; final Builder builder; Widget build(Navigator navigator, RouteBase route) => builder(navigator, route); } class RouteState extends RouteBase { - RouteState({ this.callback, this.route, Object key }) : super(key: key); + RouteState({ this.callback, this.route, this.owner }); - RouteBase route; Function callback; + RouteBase route; + StatefulComponent owner; Widget build(Navigator navigator, RouteBase route) => null; @@ -144,9 +143,8 @@ class Transition extends AnimatedComponent { } class HistoryEntry { - HistoryEntry({ this.route, this.key }); + HistoryEntry({ this.route }); final RouteBase route; - final int key; bool transitionFinished = false; // TODO(jackson): Keep track of the requested transition } @@ -158,12 +156,11 @@ class NavigationState { if (route.name != null) namedRoutes[route.name] = route; } - history.add(new HistoryEntry(route: routes[0], key: _lastKey++)); + history.add(new HistoryEntry(route: routes[0])); } List history = new List(); int historyIndex = 0; - int _lastKey = 0; Map namedRoutes = new Map(); RouteBase get currentRoute => history[historyIndex].route; @@ -176,7 +173,7 @@ class NavigationState { } void push(RouteBase route) { - HistoryEntry historyEntry = new HistoryEntry(route: route, key: _lastKey++); + HistoryEntry historyEntry = new HistoryEntry(route: route); history.insert(historyIndex + 1, historyEntry); historyIndex++; } @@ -203,9 +200,9 @@ class Navigator extends StatefulComponent { RouteBase get currentRoute => state.currentRoute; - void pushState(Object key, Function callback) { + void pushState(StatefulComponent owner, Function callback) { RouteBase route = new RouteState( - key: key, + owner: owner, callback: callback, route: state.currentRoute ); @@ -245,7 +242,7 @@ class Navigator extends StatefulComponent { if (content == null) continue; Transition transition = new Transition( - key: historyEntry.key.toString(), + key: historyEntry.hashCode.toString(), // TODO(ianh): make it not collide content: content, direction: (i <= state.historyIndex) ? TransitionDirection.forward : TransitionDirection.reverse, interactive: (i == state.historyIndex), diff --git a/packages/flutter/lib/widgets/popup_menu.dart b/packages/flutter/lib/widgets/popup_menu.dart index 85e9bd70c6..49d6aa97b8 100644 --- a/packages/flutter/lib/widgets/popup_menu.dart +++ b/packages/flutter/lib/widgets/popup_menu.dart @@ -122,8 +122,9 @@ class PopupMenu extends AnimatedComponent { PopupMenuStatus status = _status; if (_lastStatus != null && status != _lastStatus) { if (status == PopupMenuStatus.inactive && - navigator != null && - navigator.currentRoute.key == this) + navigator != null && + navigator.currentRoute is RouteState && + (navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer navigator.pop(); if (onStatusChanged != null) onStatusChanged(status); From 6d304c03acb1ea1eff06752ad816132fb041510a Mon Sep 17 00:00:00 2001 From: Hixie Date: Tue, 21 Jul 2015 15:13:01 -0700 Subject: [PATCH 04/22] Remove redundant operator== and hashCode functions in card example. It turns out that we aren't really using these. The identity logic is sufficient. Also, add some asserts for a crash I had once but couldn't reproduce, in case that helps catch it next time. --- packages/flutter/example/widgets/card_collection.dart | 2 -- packages/flutter/lib/animation/timeline.dart | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/flutter/example/widgets/card_collection.dart b/packages/flutter/example/widgets/card_collection.dart index 609993114a..c3b7cb2fad 100644 --- a/packages/flutter/example/widgets/card_collection.dart +++ b/packages/flutter/example/widgets/card_collection.dart @@ -28,8 +28,6 @@ class CardModel { AnimationPerformance performance; String get label => "Item $value"; String get key => value.toString(); - bool operator ==(other) => other is CardModel && other.value == value; - int get hashCode => 373 * 37 * value.hashCode; } class ShrinkingCard extends AnimatedComponent { diff --git a/packages/flutter/lib/animation/timeline.dart b/packages/flutter/lib/animation/timeline.dart index 680130d76b..1ea2039993 100644 --- a/packages/flutter/lib/animation/timeline.dart +++ b/packages/flutter/lib/animation/timeline.dart @@ -54,11 +54,12 @@ class Timeline { double end: 1.0 }) { assert(!_animation.isAnimating); - + assert(duration > Duration.ZERO); return _animation.start(new TweenSimulation(duration, begin, end)); } Future animateTo(double target, { Duration duration }) { + assert(duration > Duration.ZERO); return _start(duration: duration, begin: value, end: target); } From 8f85f34d278ac11e2da8116945f9074a34021406 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Tue, 21 Jul 2015 16:25:16 -0700 Subject: [PATCH 05/22] Fix 2 crashers found by Hixie's fuzzer. The first one is that we weren't setting up a FontCachePurgePreventer during drawText. It's not clear that this is the correct fix, since Blink doesn't have this FontCachePurgePreventer here either, but it's also possible that they would hit this same ASSERT and just not care (since ASSERTs are disabled on clusterfuzz). The second fix is making ExceptionState actually track whether it has thrown an exception or not. The c++ code was depending on this working in order to return early from dom functions and not crash! R=abarth@google.com --- packages/flutter/example/raw/mutating-dom.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/flutter/example/raw/mutating-dom.dart b/packages/flutter/example/raw/mutating-dom.dart index 0d27a3f008..6de893c478 100644 --- a/packages/flutter/example/raw/mutating-dom.dart +++ b/packages/flutter/example/raw/mutating-dom.dart @@ -48,9 +48,12 @@ void doFrame(double timeStamp) { node = root; } else if (node != root && other != null && pickThis(0.1)) { report("insertBefore()"); - node.insertBefore([other]); + try { + node.insertBefore([other]); + } catch (_) { + } break; - } else if (pickThis(0.001)) { + } else if (node != root && pickThis(0.001)) { report("remove()"); node.remove(); } else if (node is sky.Element) { @@ -148,7 +151,7 @@ void doFrame(double timeStamp) { break; } } else { - assert(node is sky.Text); // + assert(node is sky.Text); final sky.Text text = node; if (pickThis(0.1)) { report("appending a new text node (ASCII)"); From b26bae8a45d5812eb9341a5100478ffa92a471cd Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Tue, 21 Jul 2015 16:42:51 -0700 Subject: [PATCH 06/22] Fixes issues with invalidating matrix for SpriteBox --- .../flutter/example/game/lib/sprite_box.dart | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/flutter/example/game/lib/sprite_box.dart b/packages/flutter/example/game/lib/sprite_box.dart index c35d9e90cf..aa180c4875 100644 --- a/packages/flutter/example/game/lib/sprite_box.dart +++ b/packages/flutter/example/game/lib/sprite_box.dart @@ -39,6 +39,7 @@ class SpriteBox extends RenderBox { // Add new references _addSpriteBoxReference(_rootNode); + markNeedsLayout(); } // Tracking of frame rate and updates @@ -55,7 +56,7 @@ class SpriteBox extends RenderBox { _transformMode = value; // Invalidate stuff - if (attached) performLayout(); + markNeedsLayout(); } /// The transform mode used by the [SpriteBox]. @@ -68,7 +69,10 @@ class SpriteBox extends RenderBox { Rect _visibleArea; - Rect get visibleArea => _visibleArea; + Rect get visibleArea { + if (_visibleArea == null) _calcTransformMatrix(); + return _visibleArea; + } // Setup @@ -150,6 +154,8 @@ class SpriteBox extends RenderBox { } void handleEvent(Event event, _SpriteBoxHitTestEntry entry) { + if (!attached) return; + if (event is PointerEvent) { if (event.type == 'pointerdown') { @@ -212,10 +218,13 @@ class SpriteBox extends RenderBox { /// var matrix = mySpriteBox.transformMatrix; Matrix4 get transformMatrix { // Get cached matrix if available - if (_transformMatrix != null) { - return _transformMatrix; + if (_transformMatrix == null) { + _calcTransformMatrix(); } + return _transformMatrix; + } + void _calcTransformMatrix() { _transformMatrix = new Matrix4.identity(); // Calculate matrix @@ -273,13 +282,17 @@ class SpriteBox extends RenderBox { break; } + _visibleArea = new Rect.fromLTRB(-offsetX / scaleX, + -offsetY / scaleY, + systemWidth + offsetX / scaleX, + systemHeight + offsetY / scaleY); + _transformMatrix.translate(offsetX, offsetY); _transformMatrix.scale(scaleX, scaleY); - - return _transformMatrix; } void _invalidateTransformMatrix() { + _visibleArea = null; _transformMatrix = null; _rootNode._invalidateToBoxTransformMatrix(); } From 271812259b450c1c6ec4ea8230942db3411085b1 Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Tue, 21 Jul 2015 16:45:53 -0700 Subject: [PATCH 07/22] Fixes issues in demo game and adds heads up display --- .../example/game/lib/game_demo_world.dart | 52 ++++++++++++++++++- packages/flutter/example/game/main.dart | 11 ++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/packages/flutter/example/game/lib/game_demo_world.dart b/packages/flutter/example/game/lib/game_demo_world.dart index db93d6f2fb..e449ae4144 100644 --- a/packages/flutter/example/game/lib/game_demo_world.dart +++ b/packages/flutter/example/game/lib/game_demo_world.dart @@ -27,6 +27,7 @@ class GameDemoWorld extends NodeWithSize { sky.Image _imgNebula; SpriteSheet _spriteSheet; + SpriteSheet _spriteSheetUI; Navigator _navigator; // Inputs @@ -46,8 +47,10 @@ class GameDemoWorld extends NodeWithSize { int _numFrames = 0; bool _isGameOver = false; - GameDemoWorld(App app, this._navigator, ImageMap images, this._spriteSheet) : super(new Size(_gameSizeWidth, _gameSizeHeight)) { + // Heads up display + Hud _hud; + GameDemoWorld(App app, this._navigator, ImageMap images, this._spriteSheet, this._spriteSheetUI) : super(new Size(_gameSizeWidth, _gameSizeHeight)) { // Fetch images _imgNebula = images["assets/nebula.png"]; @@ -81,6 +84,10 @@ class GameDemoWorld extends NodeWithSize { userInteractionEnabled = true; handleMultiplePointers = true; + + _hud = new Hud(_spriteSheetUI); + _hud.zPosition = 1000.0; + addChild(_hud); } // Methods for adding game objects @@ -585,6 +592,49 @@ class StarField extends Node { } } +class Hud extends NodeWithSize { + SpriteSheet spriteSheetUI; + Sprite sprtBgScore; + Sprite sprtBgShield; + + int _score = 0; + + int get score => _score; + + set score(int score) { + _score = score; + _updateHud(); + } + + Hud(this.spriteSheetUI) { + pivot = Point.origin; + + sprtBgScore = new Sprite(spriteSheetUI["scoreboard.png"]); + sprtBgScore.pivot = Point.origin; + sprtBgScore.scale = 0.6; + addChild(sprtBgScore); + + sprtBgShield = new Sprite(spriteSheetUI["bar_shield.png"]); + sprtBgShield.pivot = new Point(1.0, 0.0); + sprtBgShield.scale = 0.6; + addChild(sprtBgShield); + } + + void spriteBoxPerformedLayout() { + // Set the size and position of HUD display + position = spriteBox.visibleArea.topLeft; + size = spriteBox.visibleArea.size; + + // Position hud objects + sprtBgScore.position = new Point(20.0, 20.0); + sprtBgShield.position = new Point(size.width - 20.0, 20.0); + } + + void _updateHud() { + + } +} + class Nebula extends Node { Nebula.withImage(sky.Image img) { diff --git a/packages/flutter/example/game/main.dart b/packages/flutter/example/game/main.dart index 8cd364dd33..dfd32947b9 100644 --- a/packages/flutter/example/game/main.dart +++ b/packages/flutter/example/game/main.dart @@ -51,6 +51,7 @@ main() async { class GameDemoApp extends App { NavigationState _navigationState; + GameDemoWorld _game; void initState() { _navigationState = new NavigationState([ @@ -84,16 +85,18 @@ class GameDemoApp extends App { } Widget _buildGameScene(navigator, route) { - return new SpriteWidget( - new GameDemoWorld(_app, navigator, _loader, _spriteSheet) - ); + if (_game == null) _game = new GameDemoWorld(_app, navigator, _loader, _spriteSheet); + return new SpriteWidget(_game); } Widget _buildMainScene(navigator, route) { return new Center( child: new RaisedButton( child: new Text("Play"), - onPressed: () => navigator.pushNamed('/game') + onPressed: () { + _game = new GameDemoWorld(_app, navigator, _loader, _spriteSheet, _spriteSheetUI); + navigator.pushNamed('/game'); + } ) ); } From 4d2902f219d09b29c543fd66d114f2dd2171aaea Mon Sep 17 00:00:00 2001 From: Hixie Date: Tue, 21 Jul 2015 17:21:01 -0700 Subject: [PATCH 08/22] Many code improvements to Mine Digger. Text styles are now a global constant instead of being initialised dynamically. There are now sufficient text styles for 8 mines around a square. I coallesced Game and MineDiggerApp. Used an enum instead of constants for the cell state. Used setState() instead of scheduleBuild(). Used an O(N) algorithm for mine laying instead of the previous potentially-never-ending algorithm. Moved the listener on the cells to the app, so that the logic survives a rebuild. Various other minor changes. --- .../flutter/example/mine_digger/lib/main.dart | 323 +++++++++--------- 1 file changed, 158 insertions(+), 165 deletions(-) diff --git a/packages/flutter/example/mine_digger/lib/main.dart b/packages/flutter/example/mine_digger/lib/main.dart index 0db72e2895..3219837fa3 100644 --- a/packages/flutter/example/mine_digger/lib/main.dart +++ b/packages/flutter/example/mine_digger/lib/main.dart @@ -9,125 +9,152 @@ import 'package:sky/painting/text_style.dart'; import 'package:sky/rendering/flex.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/widgets/basic.dart'; +import 'package:sky/widgets/widget.dart'; import 'package:sky/widgets/scaffold.dart'; import 'package:sky/widgets/task_description.dart'; import 'package:sky/widgets/theme.dart'; import 'package:sky/widgets/tool_bar.dart'; -// Classic minesweeper-inspired game. The mouse controls are standard except -// for left + right combo which is not implemented. For touch, the duration of -// the pointer determines probing versus flagging. +// Classic minesweeper-inspired game. The mouse controls are standard +// except for left + right combo which is not implemented. For touch, +// the duration of the pointer determines probing versus flagging. // -// There are only 3 classes to understand. Game, which is contains all the -// logic and two UI classes: CoveredMineNode and ExposedMineNode, none of them -// holding state. +// There are only 3 classes to understand. MineDiggerApp, which is +// contains all the logic and two classes that describe the mines: +// CoveredMineNode and ExposedMineNode, none of them holding state. + +// Colors for each mine count (0-8): +const List textStyles = const [ + const TextStyle(color: const Color(0xFF555555), fontWeight: bold), + const TextStyle(color: const Color(0xFF0094FF), fontWeight: bold), // blue + const TextStyle(color: const Color(0xFF13A023), fontWeight: bold), // green + const TextStyle(color: const Color(0xFFDA1414), fontWeight: bold), // red + const TextStyle(color: const Color(0xFF1E2347), fontWeight: bold), // black + const TextStyle(color: const Color(0xFF7F0037), fontWeight: bold), // dark red + const TextStyle(color: const Color(0xFF000000), fontWeight: bold), + const TextStyle(color: const Color(0xFF000000), fontWeight: bold), + const TextStyle(color: const Color(0xFF000000), fontWeight: bold), +]; + +enum CellState { covered, exploded, cleared, flagged, shown } + +class MineDiggerApp extends App { + + void initState() { + resetGame(); + } -class Game { static const int rows = 9; static const int cols = 9; static const int totalMineCount = 11; - static const int coveredCell = 0; - static const int explodedCell = 1; - static const int clearedCell = 2; - static const int flaggedCell = 3; - static const int shownCell = 4; - - static final List textStyles = new List(); - - final App app; - bool alive; bool hasWon; int detectedCount; - int randomSeed; // |cells| keeps track of the positions of the mines. List> cells; // |uiState| keeps track of the visible player progess. - List> uiState; + List> uiState; - Game(this.app) { - randomSeed = 22; - // Colors for each mine count: - // 0 - none, 1 - blue, 2-green, 3-red, 4-black, 5-dark red .. etc. - textStyles.add( - new TextStyle(color: const Color(0xFF555555), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFF0094FF), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFF13A023), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFFDA1414), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFF1E2347), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFF7F0037), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFFE93BE9), fontWeight: bold)); - initialize(); - } - - void initialize() { + void resetGame() { alive = true; hasWon = false; detectedCount = 0; // Build the arrays. cells = new List>(); - uiState = new List>(); + uiState = new List>(); for (int iy = 0; iy != rows; iy++) { cells.add(new List()); - uiState.add(new List()); + uiState.add(new List()); for (int ix = 0; ix != cols; ix++) { cells[iy].add(false); - uiState[iy].add(coveredCell); + uiState[iy].add(CellState.covered); } } // Place the mines. - Random random = new Random(++randomSeed); - for (int mc = 0; mc != totalMineCount; mc++) { - int rx = random.nextInt(rows); - int ry = random.nextInt(cols); - if (cells[ry][rx]) { - // Mine already there. Try again. - --mc; - } else { - cells[ry][rx] = true; + Random random = new Random(); + int cellsRemaining = rows * cols; + int minesRemaining = totalMineCount; + for (int x = 0; x < cols; x += 1) { + for (int y = 0; y < rows; y += 1) { + if (random.nextInt(cellsRemaining) < minesRemaining) { + cells[y][x] = true; + minesRemaining -= 1; + if (minesRemaining <= 0) + return; + } + cellsRemaining -= 1; } } + assert(false); + } + + Stopwatch longPressStopwatch; + + PointerEventListener _pointerDownHandlerFor(int posX, int posY) { + return (sky.PointerEvent event) { + if (event.buttons == 1) { + probe(posX, posY); + } else if (event.buttons == 2) { + flag(posX, posY); + } else { + // Touch event. + longPressStopwatch = new Stopwatch()..start(); + } + }; + } + + PointerEventListener _pointerUpHandlerFor(int posX, int posY) { + return (sky.PointerEvent event) { + if (longPressStopwatch == null) + return; + // Pointer down was a touch event. + if (longPressStopwatch.elapsedMilliseconds < 250) { + probe(posX, posY); + } else { + // Long press flags. + flag(posX, posY); + } + longPressStopwatch = null; + }; } Widget buildBoard() { bool hasCoveredCell = false; - List flexRows = new List(); + List flexRows = []; for (int iy = 0; iy != 9; iy++) { - List row = new List(); + List row = []; for (int ix = 0; ix != 9; ix++) { - int state = uiState[iy][ix]; + CellState state = uiState[iy][ix]; int count = mineCount(ix, iy); - if (!alive) { - if (state != explodedCell) - state = cells[iy][ix] ? shownCell : state; + if (state != CellState.exploded) + state = cells[iy][ix] ? CellState.shown : state; } - - if (state == coveredCell) { + if (state == CellState.covered) { + row.add(new Listener( + onPointerDown: _pointerDownHandlerFor(ix, iy), + onPointerUp: _pointerUpHandlerFor(ix, iy), + child: new CoveredMineNode( + flagged: false, + posX: ix, + posY: iy + ) + )); + // Mutating |hasCoveredCell| here is hacky, but convenient, same + // goes for mutating |hasWon| below. + hasCoveredCell = true; + } else if (state == CellState.flagged) { row.add(new CoveredMineNode( - this, - flagged: false, - posX: ix, posY: iy)); - // Mutating |hasCoveredCell| here is hacky, but convenient, same - // goes for mutating |hasWon| below. - hasCoveredCell = true; - } else if (state == flaggedCell) { - row.add(new CoveredMineNode( - this, flagged: true, - posX: ix, posY: iy)); + posX: ix, posY: iy) + ); } else { row.add(new ExposedMineNode( state: state, - count: count)); + count: count) + ); } } flexRows.add( @@ -147,33 +174,32 @@ class Game { } return new Container( - key: 'minefield', padding: new EdgeDims.all(10.0), margin: new EdgeDims.all(10.0), decoration: new BoxDecoration(backgroundColor: const Color(0xFF6B6B6B)), child: new Flex( flexRows, - direction: FlexDirection.vertical, - key: 'flxv')); + direction: FlexDirection.vertical + ) + ); } Widget buildToolBar() { - String banner = hasWon ? + String toolbarCaption = hasWon ? 'Awesome!!' : alive ? 'Mine Digger [$detectedCount-$totalMineCount]': 'Kaboom! [press here]'; return new ToolBar( // FIXME: Strange to have the toolbar be tapable. center: new Listener( - onPointerDown: handleBannerPointerDown, - child: new Text(banner, style: Theme.of(this.app).text.title) + onPointerDown: handleToolbarPointerDown, + child: new Text(toolbarCaption, style: Theme.of(this).text.title) ) ); } - Widget buildUI() { - // FIXME: We need to build the board before we build the toolbar because - // we compute the win state during build step. + Widget build() { + // We build the board before we build the toolbar because we compute the win state during build step. Widget board = buildBoard(); return new TaskDescription( label: 'Mine Digger', @@ -187,39 +213,42 @@ class Game { ); } - void handleBannerPointerDown(sky.PointerEvent event) { - initialize(); - app.scheduleBuild(); + void handleToolbarPointerDown(sky.PointerEvent event) { + setState(() { + resetGame(); + }); } // User action. The user uncovers the cell which can cause losing the game. void probe(int x, int y) { if (!alive) return; - if (uiState[y][x] == flaggedCell) + if (uiState[y][x] == CellState.flagged) return; - // Allowed to probe. - if (cells[y][x]) { - // Probed on a mine --> dead!! - uiState[y][x] = explodedCell; - alive = false; - } else { - // No mine, uncover nearby if possible. - cull(x, y); - } - app.scheduleBuild(); + setState(() { + // Allowed to probe. + if (cells[y][x]) { + // Probed on a mine --> dead!! + uiState[y][x] = CellState.exploded; + alive = false; + } else { + // No mine, uncover nearby if possible. + cull(x, y); + } + }); } // User action. The user is sure a mine is at this location. void flag(int x, int y) { - if (uiState[y][x] == flaggedCell) { - uiState[y][x] = coveredCell; - --detectedCount; - } else { - uiState[y][x] = flaggedCell; - ++detectedCount; - } - app.scheduleBuild(); + setState(() { + if (uiState[y][x] == CellState.flagged) { + uiState[y][x] = CellState.covered; + --detectedCount; + } else { + uiState[y][x] = CellState.flagged; + ++detectedCount; + } + }); } // Recursively uncovers cells whose totalMineCount is zero. @@ -229,9 +258,9 @@ class Game { if ((y < 0) || (y > cols - 1)) return; - if (uiState[y][x] == clearedCell) + if (uiState[y][x] == CellState.cleared) return; - uiState[y][x] = clearedCell; + uiState[y][x] = CellState.cleared; if (mineCount(x, y) > 0) return; @@ -269,106 +298,70 @@ class Game { } } -Widget makeCell(Widget widget) { +Widget buildCell(Widget child) { return new Container( padding: new EdgeDims.all(1.0), height: 27.0, width: 27.0, decoration: new BoxDecoration(backgroundColor: const Color(0xFFC0C0C0)), margin: new EdgeDims.all(2.0), - child: widget); + child: child + ); } -Widget makeInnerCell(Widget widget) { +Widget buildInnerCell(Widget child) { return new Container( padding: new EdgeDims.all(1.0), margin: new EdgeDims.all(3.0), height: 17.0, width: 17.0, - child: widget); + child: child + ); } class CoveredMineNode extends Component { - final Game game; + + CoveredMineNode({ this.flagged, this.posX, this.posY }); + final bool flagged; final int posX; final int posY; - Stopwatch stopwatch; - - CoveredMineNode(this.game, {this.flagged, this.posX, this.posY}); - - void _handlePointerDown(sky.PointerEvent event) { - if (event.buttons == 1) { - game.probe(posX, posY); - } else if (event.buttons == 2) { - game.flag(posX, posY); - } else { - // Touch event. - stopwatch = new Stopwatch()..start(); - } - } - - void _handlePointerUp(sky.PointerEvent event) { - if (stopwatch == null) - return; - // Pointer down was a touch event. - if (stopwatch.elapsedMilliseconds < 250) { - game.probe(posX, posY); - } else { - // Long press flags. - game.flag(posX, posY); - } - stopwatch = null; - } Widget build() { - Widget text = flagged ? - makeInnerCell(new StyledText(elements : [Game.textStyles[5], '\u2691'])) : - null; + Widget text; + if (flagged) + text = buildInnerCell(new StyledText(elements : [textStyles[5], '\u2691'])); Container inner = new Container( margin: new EdgeDims.all(2.0), height: 17.0, width: 17.0, decoration: new BoxDecoration(backgroundColor: const Color(0xFFD9D9D9)), - child: text); + child: text + ); - return makeCell(new Listener( - child: inner, - onPointerDown: _handlePointerDown, - onPointerUp: _handlePointerUp)); + return buildCell(inner); } } class ExposedMineNode extends Component { - final int state; - final int count; - ExposedMineNode({this.state, this.count}); + ExposedMineNode({ this.state, this.count }); + + final CellState state; + final int count; Widget build() { StyledText text; - if (state == Game.clearedCell) { + if (state == CellState.cleared) { // Uncovered cell with nearby mine count. if (count != 0) - text = new StyledText(elements : [Game.textStyles[count], '$count']); + text = new StyledText(elements : [textStyles[count], '$count']); } else { // Exploded mine or shown mine for 'game over'. - int color = state == Game.explodedCell ? 3 : 0; - text = new StyledText(elements : [Game.textStyles[color], '\u2600']); + int color = state == CellState.exploded ? 3 : 0; + text = new StyledText(elements : [textStyles[color], '\u2600']); } - - return makeCell(makeInnerCell(text)); - } -} - -class MineDiggerApp extends App { - Game game; - - MineDiggerApp() { - game = new Game(this); + return buildCell(buildInnerCell(text)); } - Widget build() { - return game.buildUI(); - } } void main() { From 9ee93ebad8243659f01d23658d82ca1f4d6a8a7f Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 17:29:58 -0700 Subject: [PATCH 09/22] Roll Sky package version --- packages/flutter/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index 7ef9c6b855..4efba0c64c 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -11,4 +11,4 @@ environment: sdk: '>=1.8.0 <2.0.0' homepage: https://github.com/domokit/mojo/tree/master/sky name: sky -version: 0.0.20 +version: 0.0.21 From be8b92cd84756ea549a4baedadcc64c9af6800ae Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 19:41:13 -0700 Subject: [PATCH 10/22] Update README.md --- packages/flutter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/README.md b/packages/flutter/README.md index a70daaea72..6d8e4b4332 100644 --- a/packages/flutter/README.md +++ b/packages/flutter/README.md @@ -57,7 +57,7 @@ of the Android operating system. - Enable developer mode on your device by visiting `Settings > About phone` and tapping the `Build number` field five times. - - Enable `USB debugging` in `Settings > Developer options`. + - Enable `Android debugging` in `Settings > Developer options`. - Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device. From 0a427a0a86c4b586f5d5f0fbfade5c011bb0c58a Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 19:50:44 -0700 Subject: [PATCH 11/22] Update README.md --- packages/flutter/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/flutter/README.md b/packages/flutter/README.md index 6d8e4b4332..75f325619b 100644 --- a/packages/flutter/README.md +++ b/packages/flutter/README.md @@ -3,7 +3,9 @@ Getting started with Sky Sky apps are written in Dart. To get started, we need to set up Dart SDK: - - Install the [Dart SDK](https://www.dartlang.org/downloads/). + - Install the [Dart SDK](https://www.dartlang.org/downloads/): + - Mac: `brew tap dart-lang/dart && brew install dart` + - Linux, see [https://www.dartlang.org/downloads/linux.html](https://www.dartlang.org/downloads/linux.html) - Ensure that `$DART_SDK` is set to the path of your Dart SDK and that the `dart` and `pub` executables are on your `$PATH`. @@ -50,9 +52,9 @@ Setup your Android device Currently Sky requires an Android device running the Lollipop (or newer) version of the Android operating system. - - Install the `adb` tool from the [Android SDK](https://developer.android.com/sdk/installing/index.html) - and ensure that `adb` (inside `platform-tools` in the Android SDK) is in your - `$PATH`. + - Install the `adb` tool from the [Android SDK](https://developer.android.com/sdk/installing/index.html?pkg=tools): + - Mac: `brew install android-platform-tools` + - Linux: `sudo apt-get install android-tools-adb` - Enable developer mode on your device by visiting `Settings > About phone` and tapping the `Build number` field five times. From 665f6c33a4634c446491bacaa0d1672099bbf00b Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 19:53:25 -0700 Subject: [PATCH 12/22] Update sky_tool now that sky:// isn't a thing Instead, just use a normal http URL. --- packages/flutter/lib/sky_tool | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/sky_tool b/packages/flutter/lib/sky_tool index e57159c45b..8152b8a523 100755 --- a/packages/flutter/lib/sky_tool +++ b/packages/flutter/lib/sky_tool @@ -23,6 +23,7 @@ SKY_SERVER_PORT = 9888 OBSERVATORY_PORT = 8181 APK_NAME = 'SkyDemo.apk' ANDROID_PACKAGE = "org.domokit.sky.demo" +ANDROID_COMPONENT = '%s/%s.SkyDemoActivity' % (ANDROID_PACKAGE, ANDROID_PACKAGE) # FIXME: This assumes adb is in $PATH, we could look for ANDROID_HOME, etc? ADB_PATH = 'adb' # FIXME: Do we need to look in $DART_SDK? @@ -111,7 +112,7 @@ class Pids(object): def _url_for_path(port, root, path): relative_path = os.path.relpath(path, root) - return 'sky://localhost:%s/%s' % (port, relative_path) + return 'http://localhost:%s/%s' % (port, relative_path) class StartSky(object): @@ -193,13 +194,14 @@ class StartSky(object): pids['remote_sky_server_port'] = sky_server_port # The load happens on the remote device, use the remote port. - sky_url = _url_for_path(pids['remote_sky_server_port'], sky_server_root, + url = _url_for_path(pids['remote_sky_server_port'], sky_server_root, main_dart) subprocess.check_call([ADB_PATH, 'shell', 'am', 'start', '-a', 'android.intent.action.VIEW', - '-d', sky_url]) + '-d', url, + ANDROID_COMPONENT]) class StopSky(object): From 516e6b6e273729fb9783ae5f3c9c1f586fca3240 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 19:56:57 -0700 Subject: [PATCH 13/22] Update README.md --- packages/flutter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/README.md b/packages/flutter/README.md index 75f325619b..e65426a29d 100644 --- a/packages/flutter/README.md +++ b/packages/flutter/README.md @@ -5,7 +5,7 @@ Sky apps are written in Dart. To get started, we need to set up Dart SDK: - Install the [Dart SDK](https://www.dartlang.org/downloads/): - Mac: `brew tap dart-lang/dart && brew install dart` - - Linux, see [https://www.dartlang.org/downloads/linux.html](https://www.dartlang.org/downloads/linux.html) + - Linux: See [https://www.dartlang.org/downloads/linux.html](https://www.dartlang.org/downloads/linux.html) - Ensure that `$DART_SDK` is set to the path of your Dart SDK and that the `dart` and `pub` executables are on your `$PATH`. From bb8b9c611ccad31148e41a2698cb5fadb3363531 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 22:42:04 -0700 Subject: [PATCH 14/22] Fix type error found by dartanalyzer --strong We were declaring that the function passed to setState should return a Function. In reality, we want the function to return void (and everyone calls it with a function that returns void). --- packages/flutter/lib/widgets/widget.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/lib/widgets/widget.dart b/packages/flutter/lib/widgets/widget.dart index 6f96239056..cc9e396358 100644 --- a/packages/flutter/lib/widgets/widget.dart +++ b/packages/flutter/lib/widgets/widget.dart @@ -585,7 +585,7 @@ abstract class StatefulComponent extends Component { return super.syncChild(node, oldNode, slot); } - void setState(Function fn()) { + void setState(void fn()) { assert(!_disqualifiedFromEverAppearingAgain); fn(); scheduleBuild(); From 9fd0be564b0d30119a7af4774a00270f4c891b33 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 21 Jul 2015 22:49:00 -0700 Subject: [PATCH 15/22] Update README.md Grammar --- packages/flutter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/README.md b/packages/flutter/README.md index e65426a29d..fddf171a37 100644 --- a/packages/flutter/README.md +++ b/packages/flutter/README.md @@ -46,7 +46,7 @@ The `HelloWorldApp` builds a `Text` widget containing the traditional `Hello, wo string and centers it on the screen using a `Center` widget. To learn more about the widget system, please see the [widgets tutorial](lib/widgets/README.md). -Setup your Android device +Setting up your Android device ------------------------- Currently Sky requires an Android device running the Lollipop (or newer) version From 839e997e7863d4cc3a40060cd5f269954efcc1ae Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Wed, 22 Jul 2015 11:52:34 -0400 Subject: [PATCH 16/22] rebase --- packages/flutter/BUILD.gn | 1 - .../example/stocks/lib/stock_home.dart | 37 +++--- .../lib/widgets/animation_builder.dart | 115 ------------------ packages/flutter/lib/widgets/drawer.dart | 12 ++ packages/flutter/lib/widgets/snack_bar.dart | 95 ++++++++++++--- 5 files changed, 106 insertions(+), 154 deletions(-) delete mode 100644 packages/flutter/lib/widgets/animation_builder.dart diff --git a/packages/flutter/BUILD.gn b/packages/flutter/BUILD.gn index 8ee6c835fd..020af51ead 100644 --- a/packages/flutter/BUILD.gn +++ b/packages/flutter/BUILD.gn @@ -52,7 +52,6 @@ dart_pkg("sky") { "lib/theme/view_configuration.dart", "lib/widgets/animated_component.dart", "lib/widgets/animated_container.dart", - "lib/widgets/animation_builder.dart", "lib/widgets/basic.dart", "lib/widgets/block_viewport.dart", "lib/widgets/button_base.dart", diff --git a/packages/flutter/example/stocks/lib/stock_home.dart b/packages/flutter/example/stocks/lib/stock_home.dart index 4ce3187ad6..7d8d17a2ca 100644 --- a/packages/flutter/example/stocks/lib/stock_home.dart +++ b/packages/flutter/example/stocks/lib/stock_home.dart @@ -3,9 +3,6 @@ // found in the LICENSE file. import 'package:sky/editing/input.dart'; -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/widgets/animated_component.dart'; -import 'package:sky/widgets/animation_builder.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/drawer.dart'; @@ -35,7 +32,7 @@ typedef void ModeUpdater(StockMode mode); const Duration _kSnackbarSlideDuration = const Duration(milliseconds: 200); -class StockHome extends AnimatedComponent { +class StockHome extends StatefulComponent { StockHome(this.navigator, this.stocks, this.stockMode, this.modeUpdater); @@ -54,7 +51,8 @@ class StockHome extends AnimatedComponent { bool _isSearching = false; String _searchQuery; - AnimationBuilder _snackbarTransform; + SnackBarStatus _snackBarStatus; + bool _isSnackBarShowing = false; // Should it be showing? void _handleSearchBegin() { navigator.pushState(this, (_) { @@ -140,6 +138,7 @@ class StockHome extends AnimatedComponent { Drawer buildDrawer() { if (_drawerStatus == DrawerStatus.inactive) return null; + assert(_drawerShowing); // TODO(mpcomplete): this is always true return new Drawer( level: 3, showing: _drawerShowing, @@ -264,40 +263,34 @@ class StockHome extends AnimatedComponent { void _handleUndo() { setState(() { - _snackbarTransform = null; + _isSnackBarShowing = false; }); } Widget buildSnackBar() { - if (_snackbarTransform == null) + if (_snackBarStatus == SnackBarStatus.inactive) return null; - return _snackbarTransform.build( - new SnackBar( - content: new Text("Stock purchased!"), - actions: [new SnackBarAction(label: "UNDO", onPressed: _handleUndo)] - )); + return new SnackBar( + showing: _isSnackBarShowing, + content: new Text("Stock purchased!"), + actions: [new SnackBarAction(label: "UNDO", onPressed: _handleUndo)], + onStatusChanged: (status) { setState(() { _snackBarStatus = status; }); } + ); } void _handleStockPurchased() { setState(() { - _snackbarTransform = new AnimationBuilder() - ..position = new AnimatedValue(const Point(0.0, 45.0), end: Point.origin); - var performance = _snackbarTransform.createPerformance( - [_snackbarTransform.position], duration: _kSnackbarSlideDuration); - watch(performance); // TODO(mpcomplete): need to unwatch - performance.play(); + _isSnackBarShowing = true; + _snackBarStatus = SnackBarStatus.active; }); } Widget buildFloatingActionButton() { - var widget = new FloatingActionButton( + return new FloatingActionButton( child: new Icon(type: 'content/add', size: 24), backgroundColor: colors.RedAccent[200], onPressed: _handleStockPurchased ); - if (_snackbarTransform != null) - widget = _snackbarTransform.build(widget); - return widget; } void addMenuToOverlays(List overlays) { diff --git a/packages/flutter/lib/widgets/animation_builder.dart b/packages/flutter/lib/widgets/animation_builder.dart deleted file mode 100644 index a0362f3684..0000000000 --- a/packages/flutter/lib/widgets/animation_builder.dart +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:vector_math/vector_math.dart'; - -import 'package:sky/animation/animated_value.dart'; -import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/painting/box_painter.dart'; -import 'package:sky/theme/shadows.dart'; -import 'package:sky/widgets/basic.dart'; - -// This class builds a Container object from a collection of optionally- -// animated properties. Use syncFields to update the Container's properties, -// which will optionally animate them using an AnimationPerformance. -class AnimationBuilder { - - AnimationBuilder(); - - AnimatedValue opacity; - AnimatedValue position; - AnimatedValue shadow; - AnimatedColor backgroundColor; - - // These don't animate, but are used to build the AnimationBuilder anyway. - double borderRadius; - Shape shape; - - Map _variableToPerformance = - new Map(); - - AnimationPerformance createPerformance(List variables, - { Duration duration }) { - AnimationPerformance performance = new AnimationPerformance() - ..duration = duration - ..variable = new AnimatedList(variables); - for (AnimatedVariable variable in variables) - _variableToPerformance[variable] = performance; - return performance; - } - - Widget build(Widget child) { - Widget current = child; - if (shadow != null || backgroundColor != null || - borderRadius != null || shape != null) { - current = new DecoratedBox( - decoration: new BoxDecoration( - borderRadius: borderRadius, - shape: shape, - boxShadow: shadow != null ? _computeShadow(shadow.value) : null, - backgroundColor: backgroundColor != null ? backgroundColor.value : null), - child: current); - } - - if (position != null) { - Matrix4 transform = new Matrix4.identity(); - transform.translate(position.value.x, position.value.y); - current = new Transform(transform: transform, child: current); - } - - if (opacity != null) { - current = new Opacity(opacity: opacity.value, child: current); - } - - return current; - } - - void updateFields({ - AnimatedValue shadow, - AnimatedColor backgroundColor, - double borderRadius, - Shape shape - }) { - _updateField(this.shadow, shadow); - _updateField(this.backgroundColor, backgroundColor); - this.borderRadius = borderRadius; - this.shape = shape; - } - - void _updateField(AnimatedValue variable, AnimatedValue sourceVariable) { - if (variable == null) - return; // TODO(mpcomplete): Should we handle transition from null? - - AnimationPerformance performance = _variableToPerformance[variable]; - if (performance == null) { - // If there's no performance, no need to animate. - if (sourceVariable != null) - variable.value = sourceVariable.value; - return; - } - - if (variable.value != sourceVariable.value) { - variable - ..begin = variable.value - ..end = sourceVariable.value; - performance - ..progress = 0.0 - ..play(); - } - } -} - -List _computeShadow(double level) { - if (level < 1.0) // shadows[1] is the first shadow - return null; - - int level1 = level.floor(); - int level2 = level.ceil(); - double t = level - level1.toDouble(); - - List shadow = new List(); - for (int i = 0; i < shadows[level1].length; ++i) - shadow.add(lerpBoxShadow(shadows[level1][i], shadows[level2][i], t)); - return shadow; -} diff --git a/packages/flutter/lib/widgets/drawer.dart b/packages/flutter/lib/widgets/drawer.dart index b45aa9f191..9bb6d21122 100644 --- a/packages/flutter/lib/widgets/drawer.dart +++ b/packages/flutter/lib/widgets/drawer.dart @@ -6,6 +6,8 @@ import 'dart:sky' as sky; import 'package:sky/animation/animated_value.dart'; import 'package:sky/animation/animation_performance.dart'; +import 'package:sky/animation/curves.dart'; +import 'package:sky/base/lerp.dart'; import 'package:sky/theme/shadows.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/widgets/animated_component.dart'; @@ -44,6 +46,16 @@ enum DrawerStatus { typedef void DrawerStatusChangedCallback(DrawerStatus status); +// TODO(mpcomplete): find a better place for this. +class AnimatedColor extends AnimatedType { + AnimatedColor(Color begin, { Color end, Curve curve: linear }) + : super(begin, end: end, curve: curve); + + void setFraction(double t) { + value = lerpColor(begin, end, t); + } +} + class Drawer extends AnimatedComponent { Drawer({ String key, diff --git a/packages/flutter/lib/widgets/snack_bar.dart b/packages/flutter/lib/widgets/snack_bar.dart index 00455f5f5e..ada76ebca2 100644 --- a/packages/flutter/lib/widgets/snack_bar.dart +++ b/packages/flutter/lib/widgets/snack_bar.dart @@ -2,13 +2,26 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:sky/animation/animation_performance.dart'; import 'package:sky/painting/text_style.dart'; import 'package:sky/theme/typography.dart' as typography; +import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/default_text_style.dart'; import 'package:sky/widgets/material.dart'; import 'package:sky/widgets/theme.dart'; +import 'package:vector_math/vector_math.dart'; + +enum SnackBarStatus { + active, + inactive, +} + +typedef void SnackBarStatusChangedCallback(SnackBarStatus status); + +const Duration _kSlideInDuration = const Duration(milliseconds: 200); + class SnackBarAction extends Component { SnackBarAction({String key, this.label, this.onPressed }) : super(key: key) { assert(label != null); @@ -29,18 +42,64 @@ class SnackBarAction extends Component { } } -class SnackBar extends Component { +class SnackBar extends AnimatedComponent { SnackBar({ String key, this.content, - this.actions + this.actions, + this.showing, + this.onStatusChanged }) : super(key: key) { assert(content != null); } - final Widget content; - final List actions; + Widget content; + List actions; + bool showing; + SnackBarStatusChangedCallback onStatusChanged; + + void syncFields(SnackBar source) { + content = source.content; + actions = source.actions; + onStatusChanged = source.onStatusChanged; + if (showing != source.showing) { + showing = source.showing; + showing ? _show() : _hide(); + } + } + + AnimatedType _position; + AnimationPerformance _performance; + + void initState() { + _position = new AnimatedType(new Point(0.0, 50.0), end: Point.origin); + _performance = new AnimationPerformance() + ..duration = _kSlideInDuration + ..variable = _position + ..addListener(_checkStatusChanged); + watch(_performance); + if (showing) + _show(); + } + + void _show() { + _performance.play(); + } + + void _hide() { + _performance.reverse(); + } + + SnackBarStatus _lastStatus; + void _checkStatusChanged() { + SnackBarStatus status = _status; + if (_lastStatus != null && status != _lastStatus && onStatusChanged != null) + onStatusChanged(status); + _lastStatus = status; + } + + SnackBarStatus get _status => _performance.isDismissed ? SnackBarStatus.inactive : SnackBarStatus.active; Widget build() { List children = [ @@ -53,18 +112,22 @@ class SnackBar extends Component { ) ) ) - ]; - if (actions != null) - children.addAll(actions); - return new Material( - level: 2, - color: const Color(0xFF323232), - type: MaterialType.canvas, - child: new Container( - margin: const EdgeDims.symmetric(horizontal: 24.0), - child: new DefaultTextStyle( - style: new TextStyle(color: Theme.of(this).accentColor), - child: new Flex(children) + ]..addAll(actions); + + Matrix4 transform = new Matrix4.identity(); + transform.translate(_position.value.x, _position.value.y); + return new Transform( + transform: transform, + child: new Material( + level: 2, + color: const Color(0xFF323232), + type: MaterialType.canvas, + child: new Container( + margin: const EdgeDims.symmetric(horizontal: 24.0), + child: new DefaultTextStyle( + style: new TextStyle(color: Theme.of(this).accentColor), + child: new Flex(children) + ) ) ) ); From b31e06a5d65d3c0b49545f73605283457dbd6447 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Thu, 16 Jul 2015 17:23:29 -0700 Subject: [PATCH 17/22] Make SnackBar animate itself. --- packages/flutter/example/stocks/lib/stock_home.dart | 4 ++-- packages/flutter/lib/widgets/drawer.dart | 10 ---------- packages/flutter/lib/widgets/snack_bar.dart | 5 +++-- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/flutter/example/stocks/lib/stock_home.dart b/packages/flutter/example/stocks/lib/stock_home.dart index 7d8d17a2ca..224ec81fff 100644 --- a/packages/flutter/example/stocks/lib/stock_home.dart +++ b/packages/flutter/example/stocks/lib/stock_home.dart @@ -51,8 +51,8 @@ class StockHome extends StatefulComponent { bool _isSearching = false; String _searchQuery; - SnackBarStatus _snackBarStatus; - bool _isSnackBarShowing = false; // Should it be showing? + SnackBarStatus _snackBarStatus = SnackBarStatus.inactive; + bool _isSnackBarShowing = false; void _handleSearchBegin() { navigator.pushState(this, (_) { diff --git a/packages/flutter/lib/widgets/drawer.dart b/packages/flutter/lib/widgets/drawer.dart index 9bb6d21122..2b7ecdc7ff 100644 --- a/packages/flutter/lib/widgets/drawer.dart +++ b/packages/flutter/lib/widgets/drawer.dart @@ -46,16 +46,6 @@ enum DrawerStatus { typedef void DrawerStatusChangedCallback(DrawerStatus status); -// TODO(mpcomplete): find a better place for this. -class AnimatedColor extends AnimatedType { - AnimatedColor(Color begin, { Color end, Curve curve: linear }) - : super(begin, end: end, curve: curve); - - void setFraction(double t) { - value = lerpColor(begin, end, t); - } -} - class Drawer extends AnimatedComponent { Drawer({ String key, diff --git a/packages/flutter/lib/widgets/snack_bar.dart b/packages/flutter/lib/widgets/snack_bar.dart index ada76ebca2..81df1d43a9 100644 --- a/packages/flutter/lib/widgets/snack_bar.dart +++ b/packages/flutter/lib/widgets/snack_bar.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:sky/animation/animated_value.dart'; import 'package:sky/animation/animation_performance.dart'; import 'package:sky/painting/text_style.dart'; import 'package:sky/theme/typography.dart' as typography; @@ -69,11 +70,11 @@ class SnackBar extends AnimatedComponent { } } - AnimatedType _position; + AnimatedValue _position; AnimationPerformance _performance; void initState() { - _position = new AnimatedType(new Point(0.0, 50.0), end: Point.origin); + _position = new AnimatedValue(new Point(0.0, 50.0), end: Point.origin); _performance = new AnimationPerformance() ..duration = _kSlideInDuration ..variable = _position From 371ef4542be5f916f5a2b8ba0046f16ee8282dbf Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Wed, 22 Jul 2015 11:55:38 -0400 Subject: [PATCH 18/22] Material animates over 200ms --- packages/flutter/lib/widgets/material.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/lib/widgets/material.dart b/packages/flutter/lib/widgets/material.dart index aa44a68b7d..33d6f8c193 100644 --- a/packages/flutter/lib/widgets/material.dart +++ b/packages/flutter/lib/widgets/material.dart @@ -49,7 +49,7 @@ class Material extends Component { Widget build() { return new AnimatedContainer( - duration: const Duration(milliseconds: 1000), + duration: const Duration(milliseconds: 200), decoration: new BoxDecoration( backgroundColor: _backgroundColor, borderRadius: edges[type], From 6a6567d776fa4d44cf254dc4ca2e4590c363094b Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Wed, 22 Jul 2015 08:59:14 -0700 Subject: [PATCH 19/22] Fixes formatting and removes redundant code in sprites --- .../example/game/lib/game_demo_world.dart | 3 +++ .../flutter/example/game/lib/sprite_box.dart | 18 ++++++++++++------ packages/flutter/example/game/main.dart | 5 ----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/flutter/example/game/lib/game_demo_world.dart b/packages/flutter/example/game/lib/game_demo_world.dart index e449ae4144..9154079d8d 100644 --- a/packages/flutter/example/game/lib/game_demo_world.dart +++ b/packages/flutter/example/game/lib/game_demo_world.dart @@ -631,7 +631,10 @@ class Hud extends NodeWithSize { } void _updateHud() { + sprtBgScore.removeAllChildren(); + String scoreStr = _score.toString(); + } } diff --git a/packages/flutter/example/game/lib/sprite_box.dart b/packages/flutter/example/game/lib/sprite_box.dart index aa180c4875..dd00bcf7be 100644 --- a/packages/flutter/example/game/lib/sprite_box.dart +++ b/packages/flutter/example/game/lib/sprite_box.dart @@ -70,7 +70,8 @@ class SpriteBox extends RenderBox { Rect _visibleArea; Rect get visibleArea { - if (_visibleArea == null) _calcTransformMatrix(); + if (_visibleArea == null) + _calcTransformMatrix(); return _visibleArea; } @@ -135,7 +136,8 @@ class SpriteBox extends RenderBox { // Add childrens that are behind this node while (i < children.length) { Node child = children[i]; - if (child.zPosition >= 0.0) break; + if (child.zPosition >= 0.0) + break; _addEventTargets(child, eventTargets); i++; } @@ -154,7 +156,8 @@ class SpriteBox extends RenderBox { } void handleEvent(Event event, _SpriteBoxHitTestEntry entry) { - if (!attached) return; + if (!attached) + return; if (event is PointerEvent) { @@ -191,7 +194,8 @@ class SpriteBox extends RenderBox { if (node.handleMultiplePointers || event.pointer == node._handlingPointer) { // Dispatch event bool consumedEvent = node.handleEvent(new SpriteBoxEvent(new Point(event.x, event.y), event.type, event.pointer)); - if (consumedEvent == null || consumedEvent) break; + if (consumedEvent == null || consumedEvent) + break; } } @@ -317,7 +321,8 @@ class SpriteBox extends RenderBox { } void _tick(double timeStamp) { - if (!attached) return; + if (!attached) + return; // Calculate the time between frames in seconds if (_lastTimeStamp == null) _lastTimeStamp = timeStamp; @@ -330,7 +335,8 @@ class SpriteBox extends RenderBox { _frameRate = 1.0/delta; // Print frame rate - if (_numFrames % 60 == 0) print("delta: $delta fps: $_frameRate"); + if (_numFrames % 60 == 0) + print("delta: $delta fps: $_frameRate"); _runActions(_rootNode, delta); _callUpdate(_rootNode, delta); diff --git a/packages/flutter/example/game/main.dart b/packages/flutter/example/game/main.dart index dfd32947b9..70bda87e99 100644 --- a/packages/flutter/example/game/main.dart +++ b/packages/flutter/example/game/main.dart @@ -85,7 +85,6 @@ class GameDemoApp extends App { } Widget _buildGameScene(navigator, route) { - if (_game == null) _game = new GameDemoWorld(_app, navigator, _loader, _spriteSheet); return new SpriteWidget(_game); } @@ -101,7 +100,3 @@ class GameDemoApp extends App { ); } } - -void resetGame() { - _app.scheduleBuild(); -} From 74575775bd4fee7da7991b90714c88c574e3489e Mon Sep 17 00:00:00 2001 From: Hixie Date: Tue, 21 Jul 2015 11:21:04 -0700 Subject: [PATCH 20/22] Introduce an explicit Key type. This fixes some theoretical bugs whereby we were using hashCode to try to get unique keys for objects, but really we wanted object identity. It also lays the groundwork for a new GlobalKey concept. I tried to keep the impact on the code minimal, which is why the "Key" constructor is actually a factory that returns a StringKey. The code has this class hierarchy: ``` KeyBase | Key--------------+---------------+ | | | StringKey ObjectKey UniqueKey ``` ...where the constructors are Key and Key.stringify (StringKey), Key.fromObjectIdentity (ObjectKey), and Key.unique (UniqueKey). We could instead of factory methods use regular constructors with the following hierarchy: ``` KeyBase | LocalKey---------+---------------+ | | | Key ObjectIdentityKey UniqueKey ``` ...with constructors Key, Key.stringify, ObjectIdentityKey, and UniqueKey, but I felt that that was maybe a more confusing hierarchy. I don't have a strong opinion on this. --- .../example/demo_launcher/lib/main.dart | 4 +- .../flutter/example/fitness/lib/home.dart | 6 +- .../flutter/example/mine_digger/lib/main.dart | 29 ++++++-- .../example/stocks/lib/stock_arrow.dart | 2 +- .../example/stocks/lib/stock_list.dart | 2 +- .../example/stocks/lib/stock_menu.dart | 2 +- .../flutter/example/stocks/lib/stock_row.dart | 2 +- .../example/widgets/block_viewport.dart | 2 +- .../example/widgets/card_collection.dart | 4 +- .../example/widgets/spinning_mixed.dart | 2 +- .../flutter/example/widgets/styled_text.dart | 2 +- .../flutter/lib/editing/editable_text.dart | 2 +- packages/flutter/lib/editing/input.dart | 4 +- .../lib/widgets/animated_component.dart | 2 +- .../lib/widgets/animated_container.dart | 2 +- packages/flutter/lib/widgets/basic.dart | 65 ++++++++-------- .../flutter/lib/widgets/block_viewport.dart | 4 +- packages/flutter/lib/widgets/button_base.dart | 2 +- packages/flutter/lib/widgets/card.dart | 2 +- packages/flutter/lib/widgets/checkbox.dart | 2 +- .../lib/widgets/default_text_style.dart | 2 +- packages/flutter/lib/widgets/dialog.dart | 2 +- packages/flutter/lib/widgets/dismissable.dart | 2 +- packages/flutter/lib/widgets/drawer.dart | 2 +- .../flutter/lib/widgets/drawer_divider.dart | 2 +- .../flutter/lib/widgets/drawer_header.dart | 2 +- packages/flutter/lib/widgets/drawer_item.dart | 2 +- .../lib/widgets/fixed_height_scrollable.dart | 2 +- packages/flutter/lib/widgets/flat_button.dart | 2 +- .../lib/widgets/floating_action_button.dart | 2 +- packages/flutter/lib/widgets/icon.dart | 4 +- packages/flutter/lib/widgets/icon_button.dart | 2 +- packages/flutter/lib/widgets/ink_well.dart | 2 +- packages/flutter/lib/widgets/material.dart | 2 +- .../flutter/lib/widgets/material_button.dart | 2 +- .../flutter/lib/widgets/modal_overlay.dart | 2 +- packages/flutter/lib/widgets/navigator.dart | 6 +- packages/flutter/lib/widgets/popup_menu.dart | 2 +- .../flutter/lib/widgets/popup_menu_item.dart | 2 +- packages/flutter/lib/widgets/radio.dart | 2 +- .../flutter/lib/widgets/raised_button.dart | 2 +- packages/flutter/lib/widgets/scaffold.dart | 2 +- packages/flutter/lib/widgets/scrollable.dart | 2 +- .../flutter/lib/widgets/scrollable_list.dart | 2 +- .../lib/widgets/scrollable_viewport.dart | 4 +- packages/flutter/lib/widgets/snack_bar.dart | 4 +- packages/flutter/lib/widgets/switch.dart | 2 +- packages/flutter/lib/widgets/tabs.dart | 10 +-- packages/flutter/lib/widgets/theme.dart | 2 +- packages/flutter/lib/widgets/toggleable.dart | 2 +- packages/flutter/lib/widgets/tool_bar.dart | 2 +- .../widgets/variable_height_scrollable.dart | 2 +- packages/flutter/lib/widgets/widget.dart | 74 +++++++++++++------ 53 files changed, 173 insertions(+), 125 deletions(-) diff --git a/packages/flutter/example/demo_launcher/lib/main.dart b/packages/flutter/example/demo_launcher/lib/main.dart index c634134af4..dde80a7bf8 100644 --- a/packages/flutter/example/demo_launcher/lib/main.dart +++ b/packages/flutter/example/demo_launcher/lib/main.dart @@ -60,9 +60,9 @@ class SkyDemo { this.description, this.textTheme, this.decoration - }) : name = name, key = name; + }) : name = name, key = new Key(name); final String name; - final String key; + final Key key; final String href; final String bundle; final String description; diff --git a/packages/flutter/example/fitness/lib/home.dart b/packages/flutter/example/fitness/lib/home.dart index 515c413505..7adbf966aa 100644 --- a/packages/flutter/example/fitness/lib/home.dart +++ b/packages/flutter/example/fitness/lib/home.dart @@ -27,7 +27,7 @@ import 'fitness_types.dart'; import 'measurement.dart'; class MeasurementList extends Component { - MeasurementList({ String key, this.measurements, this.onDismissed }) : super(key: key); + MeasurementList({ Key key, this.measurements, this.onDismissed }) : super(key: key); final List measurements; final MeasurementHandler onDismissed; @@ -49,7 +49,7 @@ class MeasurementList extends Component { class MeasurementRow extends Component { - MeasurementRow({ Measurement measurement, this.onDismissed }) : this.measurement = measurement, super(key: measurement.when.toString()); + MeasurementRow({ Measurement measurement, this.onDismissed }) : this.measurement = measurement, super(key: new Key.stringify(measurement.when)); final Measurement measurement; final MeasurementHandler onDismissed; @@ -74,7 +74,7 @@ class MeasurementRow extends Component { ]; return new Dismissable( - key: measurement.when.toString(), + key: new Key.stringify(measurement.when), onDismissed: () => onDismissed(measurement), child: new Card( child: new Container( diff --git a/packages/flutter/example/mine_digger/lib/main.dart b/packages/flutter/example/mine_digger/lib/main.dart index 3219837fa3..2de8b5e0ee 100644 --- a/packages/flutter/example/mine_digger/lib/main.dart +++ b/packages/flutter/example/mine_digger/lib/main.dart @@ -1,4 +1,3 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -57,6 +56,20 @@ class MineDiggerApp extends App { // |uiState| keeps track of the visible player progess. List> uiState; + Game(this.app) { + randomSeed = 22; + // Colors for each mine count: + // 0 - none, 1 - blue, 2-green, 3-red, 4-black, 5-dark red .. etc. + textStyles.add(new TextStyle(color: const Color(0xFF555555), fontWeight: bold)); + textStyles.add(new TextStyle(color: const Color(0xFF0094FF), fontWeight: bold)); + textStyles.add(new TextStyle(color: const Color(0xFF13A023), fontWeight: bold)); + textStyles.add(new TextStyle(color: const Color(0xFFDA1414), fontWeight: bold)); + textStyles.add(new TextStyle(color: const Color(0xFF1E2347), fontWeight: bold)); + textStyles.add(new TextStyle(color: const Color(0xFF7F0037), fontWeight: bold)); + textStyles.add(new TextStyle(color: const Color(0xFFE93BE9), fontWeight: bold)); + initialize(); + } + void resetGame() { alive = true; hasWon = false; @@ -148,13 +161,14 @@ class MineDiggerApp extends App { } else if (state == CellState.flagged) { row.add(new CoveredMineNode( flagged: true, - posX: ix, posY: iy) - ); + posX: ix, + posY: iy + )); } else { row.add(new ExposedMineNode( state: state, - count: count) - ); + count: count + )); } } flexRows.add( @@ -162,8 +176,9 @@ class MineDiggerApp extends App { row, direction: FlexDirection.horizontal, justifyContent: FlexJustifyContent.center, - key: 'flex_row($iy)' - )); + key: new Key.stringify(iy) + ) + ); } if (!hasCoveredCell) { diff --git a/packages/flutter/example/stocks/lib/stock_arrow.dart b/packages/flutter/example/stocks/lib/stock_arrow.dart index 95da330742..3959e112b7 100644 --- a/packages/flutter/example/stocks/lib/stock_arrow.dart +++ b/packages/flutter/example/stocks/lib/stock_arrow.dart @@ -12,7 +12,7 @@ import 'package:sky/widgets/basic.dart'; class StockArrow extends Component { - StockArrow({ String key, this.percentChange }) : super(key: key); + StockArrow({ Key key, this.percentChange }) : super(key: key); final double percentChange; diff --git a/packages/flutter/example/stocks/lib/stock_list.dart b/packages/flutter/example/stocks/lib/stock_list.dart index 8316de683c..d110d85656 100644 --- a/packages/flutter/example/stocks/lib/stock_list.dart +++ b/packages/flutter/example/stocks/lib/stock_list.dart @@ -10,7 +10,7 @@ import 'stock_data.dart'; import 'stock_row.dart'; class Stocklist extends Component { - Stocklist({ String key, this.stocks }) : super(key: key); + Stocklist({ Key key, this.stocks }) : super(key: key); final List stocks; diff --git a/packages/flutter/example/stocks/lib/stock_menu.dart b/packages/flutter/example/stocks/lib/stock_menu.dart index ef34d40fd3..3551726736 100644 --- a/packages/flutter/example/stocks/lib/stock_menu.dart +++ b/packages/flutter/example/stocks/lib/stock_menu.dart @@ -14,7 +14,7 @@ export 'package:sky/widgets/popup_menu.dart' show PopupMenuStatus; class StockMenu extends Component { StockMenu({ - String key, + Key key, this.showing, this.onStatusChanged, this.navigator, diff --git a/packages/flutter/example/stocks/lib/stock_row.dart b/packages/flutter/example/stocks/lib/stock_row.dart index 8e9ba64200..72ac5232aa 100644 --- a/packages/flutter/example/stocks/lib/stock_row.dart +++ b/packages/flutter/example/stocks/lib/stock_row.dart @@ -14,7 +14,7 @@ import 'stock_data.dart'; class StockRow extends Component { - StockRow({ Stock stock }) : this.stock = stock, super(key: stock.symbol); + StockRow({ Stock stock }) : this.stock = stock, super(key: new Key(stock.symbol)); final Stock stock; diff --git a/packages/flutter/example/widgets/block_viewport.dart b/packages/flutter/example/widgets/block_viewport.dart index aa7e53ab8f..cba6f19c69 100644 --- a/packages/flutter/example/widgets/block_viewport.dart +++ b/packages/flutter/example/widgets/block_viewport.dart @@ -115,7 +115,7 @@ class BlockViewportApp extends App { if (index >= lengths.length) return null; return new Listener( - key: lengths[index].toString(), + key: new Key.stringify(lengths[index]), child: new Container( decoration: new BoxDecoration( backgroundColor: new Color((0xFF000000 + 0xFFFFFF * lengths[index] / kMaxLength).round()) diff --git a/packages/flutter/example/widgets/card_collection.dart b/packages/flutter/example/widgets/card_collection.dart index c3b7cb2fad..4d040b2c76 100644 --- a/packages/flutter/example/widgets/card_collection.dart +++ b/packages/flutter/example/widgets/card_collection.dart @@ -27,13 +27,13 @@ class CardModel { Color color; AnimationPerformance performance; String get label => "Item $value"; - String get key => value.toString(); + Key get key => new Key.fromObjectIdentity(this); } class ShrinkingCard extends AnimatedComponent { ShrinkingCard({ - String key, + Key key, CardModel this.card, Function this.onUpdated, Function this.onCompleted diff --git a/packages/flutter/example/widgets/spinning_mixed.dart b/packages/flutter/example/widgets/spinning_mixed.dart index c8848ea194..5d5866c95b 100644 --- a/packages/flutter/example/widgets/spinning_mixed.dart +++ b/packages/flutter/example/widgets/spinning_mixed.dart @@ -24,7 +24,7 @@ void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int // Solid colour, Widget version class Rectangle extends Component { - Rectangle(this.color, { String key }) : super(key: key); + Rectangle(this.color, { Key key }) : super(key: key); final Color color; Widget build() { return new Flexible( diff --git a/packages/flutter/example/widgets/styled_text.dart b/packages/flutter/example/widgets/styled_text.dart index bcddf047bc..5a639d143b 100644 --- a/packages/flutter/example/widgets/styled_text.dart +++ b/packages/flutter/example/widgets/styled_text.dart @@ -52,7 +52,7 @@ HAL: This mission is too important for me to allow you to jeopardize it.'''; Component toStyledText(String name, String text) { TextStyle lineStyle = (name == "Dave") ? daveStyle : halStyle; return new StyledText( - key: text, + key: new Key(text), elements: [lineStyle, [boldStyle, [underlineStyle, name], ":"], text] ); } diff --git a/packages/flutter/lib/editing/editable_text.dart b/packages/flutter/lib/editing/editable_text.dart index a3389666c9..9b43313dc1 100644 --- a/packages/flutter/lib/editing/editable_text.dart +++ b/packages/flutter/lib/editing/editable_text.dart @@ -18,7 +18,7 @@ const _kCursorWidth = 1.0; class EditableText extends StatefulComponent { EditableText({ - String key, + Key key, this.value, this.focused: false, this.style, diff --git a/packages/flutter/lib/editing/input.dart b/packages/flutter/lib/editing/input.dart index 992f0cbfb7..2ca7e07dac 100644 --- a/packages/flutter/lib/editing/input.dart +++ b/packages/flutter/lib/editing/input.dart @@ -25,7 +25,7 @@ class Input extends StatefulComponent { // Never makes sense to have both a localKey and a globalKey. // Possibly a class HeroKey who functions as a UUID. - Input({String key, + Input({Key key, this.placeholder, this.onChanged, this.focused}) @@ -75,7 +75,7 @@ class Input extends StatefulComponent { if (placeholder != null && _value.isEmpty) { Widget child = new Opacity( - key: "placeholder", + key: new Key('placeholder'), child: new Text(placeholder, style: textStyle), opacity: themeData.hintOpacity ); diff --git a/packages/flutter/lib/widgets/animated_component.dart b/packages/flutter/lib/widgets/animated_component.dart index 37e077f41f..92683e0945 100644 --- a/packages/flutter/lib/widgets/animated_component.dart +++ b/packages/flutter/lib/widgets/animated_component.dart @@ -7,7 +7,7 @@ import 'package:sky/widgets/basic.dart'; abstract class AnimatedComponent extends StatefulComponent { - AnimatedComponent({ String key }) : super(key: key); + AnimatedComponent({ Key key }) : super(key: key); void syncFields(AnimatedComponent source) { } diff --git a/packages/flutter/lib/widgets/animated_container.dart b/packages/flutter/lib/widgets/animated_container.dart index d493a6857c..e55ba7dc4d 100644 --- a/packages/flutter/lib/widgets/animated_container.dart +++ b/packages/flutter/lib/widgets/animated_container.dart @@ -77,7 +77,7 @@ class ImplicitlyAnimatedValue { class AnimatedContainer extends AnimatedComponent { AnimatedContainer({ - String key, + Key key, this.child, this.duration, this.constraints, diff --git a/packages/flutter/lib/widgets/basic.dart b/packages/flutter/lib/widgets/basic.dart index 8e3e8f7866..847bf76489 100644 --- a/packages/flutter/lib/widgets/basic.dart +++ b/packages/flutter/lib/widgets/basic.dart @@ -22,13 +22,13 @@ import 'package:sky/widgets/widget.dart'; export 'package:sky/rendering/box.dart' show BackgroundImage, BoxConstraints, BoxDecoration, Border, BorderSide, EdgeDims; export 'package:sky/rendering/flex.dart' show FlexDirection, FlexJustifyContent, FlexAlignItems; export 'package:sky/rendering/object.dart' show Point, Offset, Size, Rect, Color, Paint, Path; -export 'package:sky/widgets/widget.dart' show Widget, Component, StatefulComponent, App, runApp, Listener, ParentDataNode; +export 'package:sky/widgets/widget.dart' show Key, Widget, Component, StatefulComponent, App, runApp, Listener, ParentDataNode; // PAINTING NODES class Opacity extends OneChildRenderObjectWrapper { - Opacity({ String key, this.opacity, Widget child }) + Opacity({ Key key, this.opacity, Widget child }) : super(key: key, child: child); final double opacity; @@ -43,7 +43,7 @@ class Opacity extends OneChildRenderObjectWrapper { } class ColorFilter extends OneChildRenderObjectWrapper { - ColorFilter({ String key, this.color, this.transferMode, Widget child }) + ColorFilter({ Key key, this.color, this.transferMode, Widget child }) : super(key: key, child: child); final Color color; @@ -60,7 +60,7 @@ class ColorFilter extends OneChildRenderObjectWrapper { } class DecoratedBox extends OneChildRenderObjectWrapper { - DecoratedBox({ String key, this.decoration, Widget child }) + DecoratedBox({ Key key, this.decoration, Widget child }) : super(key: key, child: child); final BoxDecoration decoration; @@ -75,7 +75,7 @@ class DecoratedBox extends OneChildRenderObjectWrapper { } class CustomPaint extends OneChildRenderObjectWrapper { - CustomPaint({ String key, this.callback, this.token, Widget child }) + CustomPaint({ Key key, this.callback, this.token, Widget child }) : super(key: key, child: child); final CustomPaintCallback callback; @@ -98,7 +98,7 @@ class CustomPaint extends OneChildRenderObjectWrapper { } class ClipRect extends OneChildRenderObjectWrapper { - ClipRect({ String key, Widget child }) + ClipRect({ Key key, Widget child }) : super(key: key, child: child); RenderClipRect createNode() => new RenderClipRect(); @@ -108,7 +108,7 @@ class ClipRect extends OneChildRenderObjectWrapper { } class ClipRRect extends OneChildRenderObjectWrapper { - ClipRRect({ String key, this.xRadius, this.yRadius, Widget child }) + ClipRRect({ Key key, this.xRadius, this.yRadius, Widget child }) : super(key: key, child: child); final double xRadius; @@ -125,7 +125,7 @@ class ClipRRect extends OneChildRenderObjectWrapper { } class ClipOval extends OneChildRenderObjectWrapper { - ClipOval({ String key, Widget child }) + ClipOval({ Key key, Widget child }) : super(key: key, child: child); RenderClipOval createNode() => new RenderClipOval(); @@ -138,7 +138,7 @@ class ClipOval extends OneChildRenderObjectWrapper { // POSITIONING AND SIZING NODES class Transform extends OneChildRenderObjectWrapper { - Transform({ String key, this.transform, Widget child }) + Transform({ Key key, this.transform, Widget child }) : super(key: key, child: child); final Matrix4 transform; @@ -153,7 +153,7 @@ class Transform extends OneChildRenderObjectWrapper { } class Padding extends OneChildRenderObjectWrapper { - Padding({ String key, this.padding, Widget child }) + Padding({ Key key, this.padding, Widget child }) : super(key: key, child: child); final EdgeDims padding; @@ -168,7 +168,7 @@ class Padding extends OneChildRenderObjectWrapper { } class Center extends OneChildRenderObjectWrapper { - Center({ String key, Widget child }) + Center({ Key key, Widget child }) : super(key: key, child: child); RenderPositionedBox createNode() => new RenderPositionedBox(); @@ -178,7 +178,7 @@ class Center extends OneChildRenderObjectWrapper { } class SizedBox extends OneChildRenderObjectWrapper { - SizedBox({ String key, this.width, this.height, Widget child }) + SizedBox({ Key key, this.width, this.height, Widget child }) : super(key: key, child: child); final double width; @@ -203,7 +203,7 @@ class SizedBox extends OneChildRenderObjectWrapper { } class ConstrainedBox extends OneChildRenderObjectWrapper { - ConstrainedBox({ String key, this.constraints, Widget child }) + ConstrainedBox({ Key key, this.constraints, Widget child }) : super(key: key, child: child); final BoxConstraints constraints; @@ -218,7 +218,7 @@ class ConstrainedBox extends OneChildRenderObjectWrapper { } class AspectRatio extends OneChildRenderObjectWrapper { - AspectRatio({ String key, this.aspectRatio, Widget child }) + AspectRatio({ Key key, this.aspectRatio, Widget child }) : super(key: key, child: child); final double aspectRatio; @@ -233,7 +233,7 @@ class AspectRatio extends OneChildRenderObjectWrapper { } class ShrinkWrapWidth extends OneChildRenderObjectWrapper { - ShrinkWrapWidth({ String key, this.stepWidth, this.stepHeight, Widget child }) + ShrinkWrapWidth({ Key key, this.stepWidth, this.stepHeight, Widget child }) : super(key: key, child: child); final double stepWidth; @@ -250,7 +250,7 @@ class ShrinkWrapWidth extends OneChildRenderObjectWrapper { } class Baseline extends OneChildRenderObjectWrapper { - Baseline({ String key, this.baseline, this.baselineType: TextBaseline.alphabetic, Widget child }) + Baseline({ Key key, this.baseline, this.baselineType: TextBaseline.alphabetic, Widget child }) : super(key: key, child: child); final double baseline; // in pixels @@ -267,7 +267,7 @@ class Baseline extends OneChildRenderObjectWrapper { } class Viewport extends OneChildRenderObjectWrapper { - Viewport({ String key, this.offset: 0.0, Widget child }) + Viewport({ Key key, this.offset: 0.0, Widget child }) : super(key: key, child: child); final double offset; @@ -282,7 +282,7 @@ class Viewport extends OneChildRenderObjectWrapper { } class SizeObserver extends OneChildRenderObjectWrapper { - SizeObserver({ String key, this.callback, Widget child }) + SizeObserver({ Key key, this.callback, Widget child }) : super(key: key, child: child); final SizeChangedCallback callback; @@ -307,7 +307,7 @@ class SizeObserver extends OneChildRenderObjectWrapper { class Container extends Component { Container({ - String key, + Key key, this.child, this.constraints, this.decoration, @@ -364,7 +364,7 @@ class Container extends Component { // LAYOUT NODES class Block extends MultiChildRenderObjectWrapper { - Block(List children, { String key }) + Block(List children, { Key key }) : super(key: key, children: children); RenderBlock createNode() => new RenderBlock(); @@ -372,7 +372,7 @@ class Block extends MultiChildRenderObjectWrapper { } class Stack extends MultiChildRenderObjectWrapper { - Stack(List children, { String key }) + Stack(List children, { Key key }) : super(key: key, children: children); RenderStack createNode() => new RenderStack(); @@ -381,7 +381,7 @@ class Stack extends MultiChildRenderObjectWrapper { class Positioned extends ParentDataNode { Positioned({ - String key, + Key key, Widget child, double top, double right, @@ -398,7 +398,7 @@ class Positioned extends ParentDataNode { class Flex extends MultiChildRenderObjectWrapper { Flex(List children, { - String key, + Key key, this.direction: FlexDirection.horizontal, this.justifyContent: FlexJustifyContent.start, this.alignItems: FlexAlignItems.center, @@ -424,12 +424,12 @@ class Flex extends MultiChildRenderObjectWrapper { } class Flexible extends ParentDataNode { - Flexible({ String key, int flex: 1, Widget child }) + Flexible({ Key key, int flex: 1, Widget child }) : super(child, new FlexBoxParentData()..flex = flex, key: key); } class Inline extends LeafRenderObjectWrapper { - Inline({ String key, this.text }) : super(key: key); + Inline({ Key key, this.text }) : super(key: key); final InlineBase text; @@ -446,7 +446,7 @@ class StyledText extends Component { // elements ::= "string" | [ *] // Where "string" is text to display and text-style is an instance of // TextStyle. The text-style applies to all of the elements that follow. - StyledText({ this.elements, String key }) : super(key: key); + StyledText({ this.elements, Key key }) : super(key: key); final dynamic elements; @@ -464,7 +464,7 @@ class StyledText extends Component { } class Text extends Component { - Text(this.data, { String key, TextStyle this.style }) : super(key: key); + Text(this.data, { Key key, TextStyle this.style }) : super(key: key); final String data; final TextStyle style; @@ -490,7 +490,7 @@ class Text extends Component { class Image extends LeafRenderObjectWrapper { Image({ sky.Image image, this.width, this.height, this.colorFilter }) : image = image, - super(key: image.hashCode.toString()); // TODO(ianh): Find a way to uniquely identify the sky.Image rather than using hashCode, which could collide + super(key: new Key.fromObjectIdentity(image)); final sky.Image image; final double width; @@ -510,7 +510,7 @@ class Image extends LeafRenderObjectWrapper { } class FutureImage extends StatefulComponent { - FutureImage({ String key, this.image, this.width, this.height, this.colorFilter }) + FutureImage({ Key key, this.image, this.width, this.height, this.colorFilter }) : super(key: key); Future image; @@ -556,7 +556,8 @@ class FutureImage extends StatefulComponent { class NetworkImage extends Component { NetworkImage({ String src, this.width, this.height, this.colorFilter }) - : src = src, super(key: src); + : src = src, + super(key: new Key(src)); final String src; final double width; @@ -576,7 +577,7 @@ class NetworkImage extends Component { class AssetImage extends Component { AssetImage({ String name, this.bundle, this.width, this.height, this.colorFilter }) : name = name, - super(key: name); + super(key: new Key(name)); final String name; final AssetBundle bundle; @@ -597,7 +598,7 @@ class AssetImage extends Component { class WidgetToRenderBoxAdapter extends LeafRenderObjectWrapper { WidgetToRenderBoxAdapter(RenderBox renderBox) : renderBox = renderBox, - super(key: renderBox.hashCode.toString()); // TODO(ianh): Find a way to uniquely identify the RenderBox rather than using hashCode, which could collide + super(key: new Key.fromObjectIdentity(renderBox)); final RenderBox renderBox; diff --git a/packages/flutter/lib/widgets/block_viewport.dart b/packages/flutter/lib/widgets/block_viewport.dart index da60075b4b..e397309beb 100644 --- a/packages/flutter/lib/widgets/block_viewport.dart +++ b/packages/flutter/lib/widgets/block_viewport.dart @@ -16,7 +16,7 @@ class _Key { const _Key(this.type, this.key); factory _Key.fromWidget(Widget widget) => new _Key(widget.runtimeType, widget.key); final Type type; - final String key; + final Key key; bool operator ==(other) => other is _Key && other.type == type && other.key == key; int get hashCode => 373 * 37 * type.hashCode + key.hashCode; String toString() => "_Key(type: $type, key: $key)"; @@ -78,7 +78,7 @@ class BlockViewportLayoutState { } class BlockViewport extends RenderObjectWrapper { - BlockViewport({ this.builder, this.startOffset, this.token, this.layoutState, String key }) + BlockViewport({ this.builder, this.startOffset, this.token, this.layoutState, Key key }) : super(key: key) { assert(this.layoutState != null); } diff --git a/packages/flutter/lib/widgets/button_base.dart b/packages/flutter/lib/widgets/button_base.dart index bcd0ac7443..aa3db42613 100644 --- a/packages/flutter/lib/widgets/button_base.dart +++ b/packages/flutter/lib/widgets/button_base.dart @@ -6,7 +6,7 @@ import 'package:sky/widgets/basic.dart'; abstract class ButtonBase extends StatefulComponent { - ButtonBase({ String key, this.highlight: false }) : super(key: key); + ButtonBase({ Key key, this.highlight: false }) : super(key: key); bool highlight; diff --git a/packages/flutter/lib/widgets/card.dart b/packages/flutter/lib/widgets/card.dart index 40ade1a969..87b196fd74 100644 --- a/packages/flutter/lib/widgets/card.dart +++ b/packages/flutter/lib/widgets/card.dart @@ -11,7 +11,7 @@ const EdgeDims kCardMargins = const EdgeDims.all(4.0); /// /// class Card extends Component { - Card({ String key, this.child, this.color }) : super(key: key); + Card({ Key key, this.child, this.color }) : super(key: key); final Widget child; final Color color; diff --git a/packages/flutter/lib/widgets/checkbox.dart b/packages/flutter/lib/widgets/checkbox.dart index 78d496a903..cdd76b7bbd 100644 --- a/packages/flutter/lib/widgets/checkbox.dart +++ b/packages/flutter/lib/widgets/checkbox.dart @@ -32,7 +32,7 @@ class Checkbox extends Toggleable { /// * `value` determines whether the checkbox is checked. /// * `onChanged` is called whenever the state of the checkbox should change. Checkbox({ - String key, + Key key, bool value, ValueChanged onChanged }) : super(key: key, value: value, onChanged: onChanged); diff --git a/packages/flutter/lib/widgets/default_text_style.dart b/packages/flutter/lib/widgets/default_text_style.dart index 840dc6451f..25f6b48cf6 100644 --- a/packages/flutter/lib/widgets/default_text_style.dart +++ b/packages/flutter/lib/widgets/default_text_style.dart @@ -9,7 +9,7 @@ import 'package:sky/widgets/widget.dart'; class DefaultTextStyle extends Inherited { DefaultTextStyle({ - String key, + Key key, this.style, Widget child }) : super(key: key, child: child) { diff --git a/packages/flutter/lib/widgets/dialog.dart b/packages/flutter/lib/widgets/dialog.dart index 4328190a61..94fe950b06 100644 --- a/packages/flutter/lib/widgets/dialog.dart +++ b/packages/flutter/lib/widgets/dialog.dart @@ -14,7 +14,7 @@ import 'package:sky/widgets/theme.dart'; /// class Dialog extends Component { Dialog({ - String key, + Key key, this.title, this.content, this.actions, diff --git a/packages/flutter/lib/widgets/dismissable.dart b/packages/flutter/lib/widgets/dismissable.dart index 9362dfc7ea..2ecf4e5b40 100644 --- a/packages/flutter/lib/widgets/dismissable.dart +++ b/packages/flutter/lib/widgets/dismissable.dart @@ -22,7 +22,7 @@ typedef void DismissedCallback(); class Dismissable extends AnimatedComponent { Dismissable({ - String key, + Key key, this.child, this.onDismissed // TODO(hansmuller): direction diff --git a/packages/flutter/lib/widgets/drawer.dart b/packages/flutter/lib/widgets/drawer.dart index b45aa9f191..8a34bdf529 100644 --- a/packages/flutter/lib/widgets/drawer.dart +++ b/packages/flutter/lib/widgets/drawer.dart @@ -46,7 +46,7 @@ typedef void DrawerStatusChangedCallback(DrawerStatus status); class Drawer extends AnimatedComponent { Drawer({ - String key, + Key key, this.children, this.showing: false, this.level: 0, diff --git a/packages/flutter/lib/widgets/drawer_divider.dart b/packages/flutter/lib/widgets/drawer_divider.dart index 3b055bc181..0acab63bc7 100644 --- a/packages/flutter/lib/widgets/drawer_divider.dart +++ b/packages/flutter/lib/widgets/drawer_divider.dart @@ -6,7 +6,7 @@ import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/theme.dart'; class DrawerDivider extends Component { - DrawerDivider({ String key }) : super(key: key); + DrawerDivider({ Key key }) : super(key: key); Widget build() { return new Container( diff --git a/packages/flutter/lib/widgets/drawer_header.dart b/packages/flutter/lib/widgets/drawer_header.dart index 4fb33d0c97..5f29433b77 100644 --- a/packages/flutter/lib/widgets/drawer_header.dart +++ b/packages/flutter/lib/widgets/drawer_header.dart @@ -12,7 +12,7 @@ import 'package:sky/widgets/theme.dart'; class DrawerHeader extends Component { - DrawerHeader({ String key, this.children }) : super(key: key); + DrawerHeader({ Key key, this.children }) : super(key: key); final List children; diff --git a/packages/flutter/lib/widgets/drawer_item.dart b/packages/flutter/lib/widgets/drawer_item.dart index d807bd89c7..1e179dc571 100644 --- a/packages/flutter/lib/widgets/drawer_item.dart +++ b/packages/flutter/lib/widgets/drawer_item.dart @@ -15,7 +15,7 @@ import 'package:sky/widgets/theme.dart'; import 'package:sky/widgets/widget.dart'; class DrawerItem extends ButtonBase { - DrawerItem({ String key, this.icon, this.children, this.onPressed, this.selected: false }) + DrawerItem({ Key key, this.icon, this.children, this.onPressed, this.selected: false }) : super(key: key); String icon; diff --git a/packages/flutter/lib/widgets/fixed_height_scrollable.dart b/packages/flutter/lib/widgets/fixed_height_scrollable.dart index d2ba07ff0b..8ed31ad725 100644 --- a/packages/flutter/lib/widgets/fixed_height_scrollable.dart +++ b/packages/flutter/lib/widgets/fixed_height_scrollable.dart @@ -10,7 +10,7 @@ import 'package:sky/widgets/scrollable.dart'; abstract class FixedHeightScrollable extends Scrollable { - FixedHeightScrollable({ String key, this.itemHeight, this.padding }) + FixedHeightScrollable({ Key key, this.itemHeight, this.padding }) : super(key: key) { assert(itemHeight != null); } diff --git a/packages/flutter/lib/widgets/flat_button.dart b/packages/flutter/lib/widgets/flat_button.dart index 4b5d39bfbf..18ac2a1c9e 100644 --- a/packages/flutter/lib/widgets/flat_button.dart +++ b/packages/flutter/lib/widgets/flat_button.dart @@ -9,7 +9,7 @@ import 'package:sky/widgets/theme.dart'; class FlatButton extends MaterialButton { FlatButton({ - String key, + Key key, Widget child, bool enabled: true, Function onPressed diff --git a/packages/flutter/lib/widgets/floating_action_button.dart b/packages/flutter/lib/widgets/floating_action_button.dart index a10d503072..d48be01024 100644 --- a/packages/flutter/lib/widgets/floating_action_button.dart +++ b/packages/flutter/lib/widgets/floating_action_button.dart @@ -16,7 +16,7 @@ const double _kSize = 56.0; class FloatingActionButton extends ButtonBase { FloatingActionButton({ - String key, + Key key, this.child, this.backgroundColor, this.onPressed diff --git a/packages/flutter/lib/widgets/icon.dart b/packages/flutter/lib/widgets/icon.dart index c460228c81..7888d4f2d0 100644 --- a/packages/flutter/lib/widgets/icon.dart +++ b/packages/flutter/lib/widgets/icon.dart @@ -19,7 +19,7 @@ class IconThemeData { class IconTheme extends Inherited { IconTheme({ - String key, + Key key, this.data, Widget child }) : super(key: key, child: child) { @@ -49,7 +49,7 @@ final AssetBundle _iconBundle = _initIconBundle(); class Icon extends Component { Icon({ - String key, + Key key, this.size, this.type: '', this.color, diff --git a/packages/flutter/lib/widgets/icon_button.dart b/packages/flutter/lib/widgets/icon_button.dart index ceee0afbcc..c63854f37f 100644 --- a/packages/flutter/lib/widgets/icon_button.dart +++ b/packages/flutter/lib/widgets/icon_button.dart @@ -12,7 +12,7 @@ import 'package:sky/widgets/widget.dart'; class IconButton extends Component { IconButton({ String icon: '', this.onPressed, this.color }) - : super(key: icon), icon = icon; + : super(key: new Key(icon)), icon = icon; final String icon; final Function onPressed; diff --git a/packages/flutter/lib/widgets/ink_well.dart b/packages/flutter/lib/widgets/ink_well.dart index 158c6e469d..86139365e0 100644 --- a/packages/flutter/lib/widgets/ink_well.dart +++ b/packages/flutter/lib/widgets/ink_well.dart @@ -126,7 +126,7 @@ class RenderInkWell extends RenderProxyBox { } class InkWell extends OneChildRenderObjectWrapper { - InkWell({ String key, Widget child }) + InkWell({ Key key, Widget child }) : super(key: key, child: child); RenderInkWell get root => super.root; diff --git a/packages/flutter/lib/widgets/material.dart b/packages/flutter/lib/widgets/material.dart index aa44a68b7d..7c536264b3 100644 --- a/packages/flutter/lib/widgets/material.dart +++ b/packages/flutter/lib/widgets/material.dart @@ -20,7 +20,7 @@ const Map edges = const { class Material extends Component { Material({ - String key, + Key key, this.child, this.type: MaterialType.card, this.level: 0, diff --git a/packages/flutter/lib/widgets/material_button.dart b/packages/flutter/lib/widgets/material_button.dart index a037b91fb5..d4e27c1fa2 100644 --- a/packages/flutter/lib/widgets/material_button.dart +++ b/packages/flutter/lib/widgets/material_button.dart @@ -11,7 +11,7 @@ import 'package:sky/widgets/material.dart'; abstract class MaterialButton extends ButtonBase { MaterialButton({ - String key, + Key key, this.child, this.enabled: true, this.onPressed diff --git a/packages/flutter/lib/widgets/modal_overlay.dart b/packages/flutter/lib/widgets/modal_overlay.dart index ccf016608b..abfee7a539 100644 --- a/packages/flutter/lib/widgets/modal_overlay.dart +++ b/packages/flutter/lib/widgets/modal_overlay.dart @@ -7,7 +7,7 @@ import 'package:sky/widgets/widget.dart'; class ModalOverlay extends Component { - ModalOverlay({ String key, this.children, this.onDismiss }) : super(key: key); + ModalOverlay({ Key key, this.children, this.onDismiss }) : super(key: key); final List children; final Function onDismiss; diff --git a/packages/flutter/lib/widgets/navigator.dart b/packages/flutter/lib/widgets/navigator.dart index 1a20b5aeb4..0d532d89d6 100644 --- a/packages/flutter/lib/widgets/navigator.dart +++ b/packages/flutter/lib/widgets/navigator.dart @@ -46,7 +46,7 @@ const Point _kTransitionStartPoint = const Point(0.0, 75.0); enum TransitionDirection { forward, reverse } class Transition extends AnimatedComponent { Transition({ - String key, + Key key, this.content, this.direction, this.onDismissed, @@ -190,7 +190,7 @@ class NavigationState { class Navigator extends StatefulComponent { - Navigator(this.state, { String key }) : super(key: key); + Navigator(this.state, { Key key }) : super(key: key); NavigationState state; @@ -242,7 +242,7 @@ class Navigator extends StatefulComponent { if (content == null) continue; Transition transition = new Transition( - key: historyEntry.hashCode.toString(), // TODO(ianh): make it not collide + key: new Key.fromObjectIdentity(historyEntry), content: content, direction: (i <= state.historyIndex) ? TransitionDirection.forward : TransitionDirection.reverse, interactive: (i == state.historyIndex), diff --git a/packages/flutter/lib/widgets/popup_menu.dart b/packages/flutter/lib/widgets/popup_menu.dart index 49d6aa97b8..db18386393 100644 --- a/packages/flutter/lib/widgets/popup_menu.dart +++ b/packages/flutter/lib/widgets/popup_menu.dart @@ -35,7 +35,7 @@ typedef void PopupMenuStatusChangedCallback(PopupMenuStatus status); class PopupMenu extends AnimatedComponent { PopupMenu({ - String key, + Key key, this.showing, this.onStatusChanged, this.items, diff --git a/packages/flutter/lib/widgets/popup_menu_item.dart b/packages/flutter/lib/widgets/popup_menu_item.dart index d04e3266a4..df20c058a0 100644 --- a/packages/flutter/lib/widgets/popup_menu_item.dart +++ b/packages/flutter/lib/widgets/popup_menu_item.dart @@ -13,7 +13,7 @@ const double kBaselineOffsetFromBottom = 20.0; class PopupMenuItem extends Component { PopupMenuItem({ - String key, + Key key, this.onPressed, this.child }) : super(key: key); diff --git a/packages/flutter/lib/widgets/radio.dart b/packages/flutter/lib/widgets/radio.dart index dd756b13bd..16e8f69f47 100644 --- a/packages/flutter/lib/widgets/radio.dart +++ b/packages/flutter/lib/widgets/radio.dart @@ -17,7 +17,7 @@ typedef void ValueChanged(value); class Radio extends ButtonBase { Radio({ - String key, + Key key, this.value, this.groupValue, this.onChanged diff --git a/packages/flutter/lib/widgets/raised_button.dart b/packages/flutter/lib/widgets/raised_button.dart index 52936c06c8..03d7b8c6ee 100644 --- a/packages/flutter/lib/widgets/raised_button.dart +++ b/packages/flutter/lib/widgets/raised_button.dart @@ -10,7 +10,7 @@ import 'package:sky/widgets/theme.dart'; class RaisedButton extends MaterialButton { RaisedButton({ - String key, + Key key, Widget child, bool enabled: true, Function onPressed diff --git a/packages/flutter/lib/widgets/scaffold.dart b/packages/flutter/lib/widgets/scaffold.dart index 524d384190..a5b9984129 100644 --- a/packages/flutter/lib/widgets/scaffold.dart +++ b/packages/flutter/lib/widgets/scaffold.dart @@ -173,7 +173,7 @@ class RenderScaffold extends RenderBox { class Scaffold extends RenderObjectWrapper { Scaffold({ - String key, + Key key, Widget body, Widget statusBar, Widget toolbar, diff --git a/packages/flutter/lib/widgets/scrollable.dart b/packages/flutter/lib/widgets/scrollable.dart index 6a687b5fa6..f5e566507e 100644 --- a/packages/flutter/lib/widgets/scrollable.dart +++ b/packages/flutter/lib/widgets/scrollable.dart @@ -27,7 +27,7 @@ enum ScrollDirection { vertical, horizontal } abstract class Scrollable extends StatefulComponent { Scrollable({ - String key, + Key key, this.direction: ScrollDirection.vertical }) : super(key: key); diff --git a/packages/flutter/lib/widgets/scrollable_list.dart b/packages/flutter/lib/widgets/scrollable_list.dart index 10ba57cb51..b897ef2ff7 100644 --- a/packages/flutter/lib/widgets/scrollable_list.dart +++ b/packages/flutter/lib/widgets/scrollable_list.dart @@ -11,7 +11,7 @@ typedef Widget ItemBuilder(T item); class ScrollableList extends FixedHeightScrollable { ScrollableList({ - String key, + Key key, this.items, this.itemBuilder, double itemHeight, diff --git a/packages/flutter/lib/widgets/scrollable_viewport.dart b/packages/flutter/lib/widgets/scrollable_viewport.dart index c7ed2adc02..208fad3e1e 100644 --- a/packages/flutter/lib/widgets/scrollable_viewport.dart +++ b/packages/flutter/lib/widgets/scrollable_viewport.dart @@ -8,7 +8,7 @@ import 'package:sky/widgets/scrollable.dart'; class ScrollableViewport extends Scrollable { - ScrollableViewport({ String key, this.child }) : super(key: key); + ScrollableViewport({ Key key, this.child }) : super(key: key); Widget child; @@ -54,7 +54,7 @@ class ScrollableViewport extends Scrollable { class ScrollableBlock extends Component { - ScrollableBlock(this.children, { String key }) : super(key: key); + ScrollableBlock(this.children, { Key key }) : super(key: key); final List children; diff --git a/packages/flutter/lib/widgets/snack_bar.dart b/packages/flutter/lib/widgets/snack_bar.dart index 00455f5f5e..ec3957aefa 100644 --- a/packages/flutter/lib/widgets/snack_bar.dart +++ b/packages/flutter/lib/widgets/snack_bar.dart @@ -10,7 +10,7 @@ import 'package:sky/widgets/material.dart'; import 'package:sky/widgets/theme.dart'; class SnackBarAction extends Component { - SnackBarAction({String key, this.label, this.onPressed }) : super(key: key) { + SnackBarAction({Key key, this.label, this.onPressed }) : super(key: key) { assert(label != null); } @@ -32,7 +32,7 @@ class SnackBarAction extends Component { class SnackBar extends Component { SnackBar({ - String key, + Key key, this.content, this.actions }) : super(key: key) { diff --git a/packages/flutter/lib/widgets/switch.dart b/packages/flutter/lib/widgets/switch.dart index 93feda85df..c603a8a898 100644 --- a/packages/flutter/lib/widgets/switch.dart +++ b/packages/flutter/lib/widgets/switch.dart @@ -26,7 +26,7 @@ class Switch extends Toggleable { // TODO(jackson): Hit-test the switch so that it can respond to both taps and swipe gestures Switch({ - String key, + Key key, bool value, ValueChanged onChanged }) : super(key: key, value: value, onChanged: onChanged); diff --git a/packages/flutter/lib/widgets/tabs.dart b/packages/flutter/lib/widgets/tabs.dart index 4bfc3b32a1..8de067c3e1 100644 --- a/packages/flutter/lib/widgets/tabs.dart +++ b/packages/flutter/lib/widgets/tabs.dart @@ -256,7 +256,7 @@ class TabBarWrapper extends MultiChildRenderObjectWrapper { this.textAndIcons, this.scrollable: false, this.onLayoutChanged, - String key + Key key }) : super(key: key, children: children); final int selectedIndex; @@ -289,7 +289,7 @@ class TabLabel { class Tab extends Component { Tab({ - String key, + Key key, this.label, this.selected: false }) : super(key: key) { @@ -347,7 +347,7 @@ class Tab extends Component { class TabBar extends Scrollable { TabBar({ - String key, + Key key, this.labels, this.selectedIndex: 0, this.onChanged, @@ -381,7 +381,7 @@ class TabBar extends Scrollable { Tab tab = new Tab( label: label, selected: tabIndex == selectedIndex, - key: label.text == null ? label.icon : label.text + key: new Key(label.text == null ? label.icon : label.text) ); return new Listener( child: tab, @@ -472,7 +472,7 @@ class TabNavigatorView { class TabNavigator extends Component { TabNavigator({ - String key, + Key key, this.views, this.selectedIndex: 0, this.onChanged, diff --git a/packages/flutter/lib/widgets/theme.dart b/packages/flutter/lib/widgets/theme.dart index 6b4fc3f735..9da448ac8d 100644 --- a/packages/flutter/lib/widgets/theme.dart +++ b/packages/flutter/lib/widgets/theme.dart @@ -11,7 +11,7 @@ export 'package:sky/theme/theme_data.dart' show ThemeData, ThemeBrightness; class Theme extends Inherited { Theme({ - String key, + Key key, this.data, Widget child }) : super(key: key, child: child) { diff --git a/packages/flutter/lib/widgets/toggleable.dart b/packages/flutter/lib/widgets/toggleable.dart index 8fd8b1c44f..61ceab4c67 100644 --- a/packages/flutter/lib/widgets/toggleable.dart +++ b/packages/flutter/lib/widgets/toggleable.dart @@ -17,7 +17,7 @@ const Duration _kCheckDuration = const Duration(milliseconds: 200); abstract class Toggleable extends AnimatedComponent { Toggleable({ - String key, + Key key, this.value, this.onChanged }) : super(key: key); diff --git a/packages/flutter/lib/widgets/tool_bar.dart b/packages/flutter/lib/widgets/tool_bar.dart index 8fec03cd80..20080e35dd 100644 --- a/packages/flutter/lib/widgets/tool_bar.dart +++ b/packages/flutter/lib/widgets/tool_bar.dart @@ -16,7 +16,7 @@ import 'package:sky/widgets/icon.dart'; class ToolBar extends Component { ToolBar({ - String key, + Key key, this.left, this.center, this.right, diff --git a/packages/flutter/lib/widgets/variable_height_scrollable.dart b/packages/flutter/lib/widgets/variable_height_scrollable.dart index 66f060f85d..e7fbfaecd8 100644 --- a/packages/flutter/lib/widgets/variable_height_scrollable.dart +++ b/packages/flutter/lib/widgets/variable_height_scrollable.dart @@ -12,7 +12,7 @@ export 'package:sky/widgets/block_viewport.dart' show BlockViewportLayoutState; class VariableHeightScrollable extends Scrollable { VariableHeightScrollable({ - String key, + Key key, this.builder, this.token, this.layoutState diff --git a/packages/flutter/lib/widgets/widget.dart b/packages/flutter/lib/widgets/widget.dart index cc9e396358..a3badf7b61 100644 --- a/packages/flutter/lib/widgets/widget.dart +++ b/packages/flutter/lib/widgets/widget.dart @@ -21,22 +21,54 @@ final bool _shouldLogRenderDuration = false; typedef Widget Builder(); typedef void WidgetTreeWalker(Widget); +abstract class KeyBase { +} + +abstract class Key extends KeyBase { + 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.stringify(Object value) => new StringKey(value.toString()); + factory Key.fromObjectIdentity(Object value) => new ObjectKey(value); + factory Key.unique() => new UniqueKey(); +} + +class StringKey extends Key { + StringKey(this.value) : super.constructor(); + final String value; + String toString() => value; + bool operator==(other) => other is StringKey && other.value == value; + int get hashCode => value.hashCode; +} + +class ObjectKey extends Key { + ObjectKey(this.value) : super.constructor(); + final Object value; + String toString() => '[Instance of ${value.runtimeType}]'; + bool operator==(other) => other is ObjectKey && identical(other.value, value); + int get hashCode => identityHashCode(value); +} + +class UniqueKey extends Key { + UniqueKey() : super.constructor(); + String toString() => '[$hashCode]'; +} + /// A base class for elements of the widget tree abstract class Widget { - Widget({ String key }) : _key = key { + Widget({ Key key }) : _key = key { assert(_isConstructedDuringBuild()); } // TODO(jackson): Remove this workaround for limitation of Dart mixins - Widget._withKey(String key) : _key = key { + Widget._withKey(Key key) : _key = key { assert(_isConstructedDuringBuild()); } // you should not build the UI tree ahead of time, build it only during build() bool _isConstructedDuringBuild() => this is AbstractWidgetRoot || this is App || _inRenderDirtyComponents || _inLayoutCallbackBuilder > 0; - String _key; + Key _key; /// A semantic identifer for this widget /// @@ -46,7 +78,7 @@ abstract class Widget { /// Assigning a key to a widget can improve performance by causing the /// framework to sync widgets that share a lot of common structure and can /// help match stateful components semantically rather than positionally. - String get key => _key; + Key get key => _key; Widget _parent; @@ -243,11 +275,11 @@ abstract class Widget { // stylistic information, etc. abstract class TagNode extends Widget { - TagNode(Widget child, { String key }) + TagNode(Widget child, { Key key }) : this.child = child, super(key: key); // TODO(jackson): Remove this workaround for limitation of Dart mixins - TagNode._withKey(Widget child, String key) + TagNode._withKey(Widget child, Key key) : this.child = child, super._withKey(key); Widget child; @@ -284,14 +316,14 @@ abstract class TagNode extends Widget { } class ParentDataNode extends TagNode { - ParentDataNode(Widget child, this.parentData, { String key }) + ParentDataNode(Widget child, this.parentData, { Key key }) : super(child, key: key); final ParentData parentData; } abstract class Inherited extends TagNode { - Inherited({ String key, Widget child }) : super._withKey(child, key); + Inherited({ Key key, Widget child }) : super._withKey(child, key); void _sync(Widget old, dynamic slot) { if (old != null && syncShouldNotify(old)) { @@ -320,7 +352,7 @@ typedef void EventListener(sky.Event e); class Listener extends TagNode { Listener({ - String key, + Key key, Widget child, EventListener onWheel, GestureEventListener onGestureFlingCancel, @@ -407,7 +439,7 @@ class Listener extends TagNode { abstract class Component extends Widget { - Component({ String key }) + Component({ Key key }) : _order = _currentOrder + 1, super._withKey(key); @@ -524,7 +556,7 @@ abstract class Component extends Widget { abstract class StatefulComponent extends Component { - StatefulComponent({ String key }) : super(key: key); + StatefulComponent({ Key key }) : super(key: key); bool _disqualifiedFromEverAppearingAgain = false; bool _isStateInitialized = false; @@ -682,7 +714,7 @@ void _scheduleComponentForRender(Component c) { // become stateful. abstract class RenderObjectWrapper extends Widget { - RenderObjectWrapper({ String key }) : super(key: key); + RenderObjectWrapper({ Key key }) : super(key: key); RenderObject createNode(); @@ -766,7 +798,7 @@ abstract class RenderObjectWrapper extends Widget { abstract class LeafRenderObjectWrapper extends RenderObjectWrapper { - LeafRenderObjectWrapper({ String key }) : super(key: key); + LeafRenderObjectWrapper({ Key key }) : super(key: key); void insertChildRoot(RenderObjectWrapper child, dynamic slot) { assert(false); @@ -780,7 +812,7 @@ abstract class LeafRenderObjectWrapper extends RenderObjectWrapper { abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { - OneChildRenderObjectWrapper({ String key, Widget child }) + OneChildRenderObjectWrapper({ Key key, Widget child }) : _child = child, super(key: key); Widget _child; @@ -828,7 +860,7 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { // In MultiChildRenderObjectWrapper subclasses, slots are RenderObject nodes // to use as the "insert before" sibling in ContainerRenderObjectMixin.add() calls - MultiChildRenderObjectWrapper({ String key, List children }) + MultiChildRenderObjectWrapper({ Key key, List children }) : this.children = children == null ? const [] : children, super(key: key) { assert(!_debugHasDuplicateIds()); @@ -867,7 +899,7 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { } bool _debugHasDuplicateIds() { - var idSet = new HashSet(); + var idSet = new HashSet(); for (var child in children) { assert(child != null); if (child.key == null) @@ -922,9 +954,9 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { nextSibling = children[endIndex].root; } - HashMap oldNodeIdMap = null; + HashMap oldNodeIdMap = null; - bool oldNodeReordered(String key) { + bool oldNodeReordered(Key key) { return oldNodeIdMap != null && oldNodeIdMap.containsKey(key) && oldNodeIdMap[key] == null; @@ -942,7 +974,7 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { if (oldNodeIdMap != null) return; - oldNodeIdMap = new HashMap(); + oldNodeIdMap = new HashMap(); for (int i = oldStartIndex; i < oldEndIndex; i++) { var node = oldChildren[i]; if (node.key != null) @@ -1047,7 +1079,7 @@ class WidgetSkyBinding extends SkyBinding { abstract class App extends StatefulComponent { - App({ String key }) : super(key: key); + App({ Key key }) : super(key: key); void _handleEvent(sky.Event event) { if (event.type == 'back') @@ -1095,7 +1127,7 @@ abstract class AbstractWidgetRoot extends StatefulComponent { } class RenderViewWrapper extends OneChildRenderObjectWrapper { - RenderViewWrapper({ String key, Widget child }) : super(key: key, child: child); + RenderViewWrapper({ Key key, Widget child }) : super(key: key, child: child); RenderView get root => super.root; RenderView createNode() => SkyBinding.instance.renderView; } From 3d0b82eb861fc1241b86529b4dffaa12283dfa94 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 22 Jul 2015 09:59:18 -0700 Subject: [PATCH 21/22] Use a null LayoutCallbackBuilderHandle in Release --- packages/flutter/lib/widgets/drawer.dart | 2 -- packages/flutter/lib/widgets/widget.dart | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/widgets/drawer.dart b/packages/flutter/lib/widgets/drawer.dart index 6405276407..8a34bdf529 100644 --- a/packages/flutter/lib/widgets/drawer.dart +++ b/packages/flutter/lib/widgets/drawer.dart @@ -6,8 +6,6 @@ import 'dart:sky' as sky; import 'package:sky/animation/animated_value.dart'; import 'package:sky/animation/animation_performance.dart'; -import 'package:sky/animation/curves.dart'; -import 'package:sky/base/lerp.dart'; import 'package:sky/theme/shadows.dart'; import 'package:sky/theme/colors.dart' as colors; import 'package:sky/widgets/animated_component.dart'; diff --git a/packages/flutter/lib/widgets/widget.dart b/packages/flutter/lib/widgets/widget.dart index a3badf7b61..1108755b92 100644 --- a/packages/flutter/lib/widgets/widget.dart +++ b/packages/flutter/lib/widgets/widget.dart @@ -631,11 +631,13 @@ int _inLayoutCallbackBuilder = 0; class LayoutCallbackBuilderHandle { bool _active = true; } LayoutCallbackBuilderHandle enterLayoutCallbackBuilder() { + LayoutCallbackBuilderHandle result; assert(() { _inLayoutCallbackBuilder += 1; + result = new LayoutCallbackBuilderHandle(); return true; }); - return new LayoutCallbackBuilderHandle(); + return result; } void exitLayoutCallbackBuilder(LayoutCallbackBuilderHandle handle) { assert(() { From 4dacd69b41f6ed52a8e1882926e03a0f4643ce2a Mon Sep 17 00:00:00 2001 From: Hixie Date: Wed, 22 Jul 2015 10:04:30 -0700 Subject: [PATCH 22/22] Don't set keys on images, etc, pre-emptively. In theory, before, if you had the same image twice in a scrolling container, you'd get an assertion with no way around it. This makes those nodes not bother making keys by default, which is cheaper and more correct. --- packages/flutter/lib/widgets/basic.dart | 15 ++++----------- packages/flutter/lib/widgets/icon_button.dart | 3 +-- packages/flutter/lib/widgets/tabs.dart | 14 ++++++-------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/packages/flutter/lib/widgets/basic.dart b/packages/flutter/lib/widgets/basic.dart index 847bf76489..5e7ba5dee0 100644 --- a/packages/flutter/lib/widgets/basic.dart +++ b/packages/flutter/lib/widgets/basic.dart @@ -488,9 +488,7 @@ class Text extends Component { } class Image extends LeafRenderObjectWrapper { - Image({ sky.Image image, this.width, this.height, this.colorFilter }) - : image = image, - super(key: new Key.fromObjectIdentity(image)); + Image({ Key key, this.image, this.width, this.height, this.colorFilter }) : super(key: key); final sky.Image image; final double width; @@ -510,8 +508,7 @@ class Image extends LeafRenderObjectWrapper { } class FutureImage extends StatefulComponent { - FutureImage({ Key key, this.image, this.width, this.height, this.colorFilter }) - : super(key: key); + FutureImage({ Key key, this.image, this.width, this.height, this.colorFilter }) : super(key: key); Future image; double width; @@ -555,9 +552,7 @@ class FutureImage extends StatefulComponent { } class NetworkImage extends Component { - NetworkImage({ String src, this.width, this.height, this.colorFilter }) - : src = src, - super(key: new Key(src)); + NetworkImage({ Key key, this.src, this.width, this.height, this.colorFilter }) : super(key: key); final String src; final double width; @@ -575,9 +570,7 @@ class NetworkImage extends Component { } class AssetImage extends Component { - AssetImage({ String name, this.bundle, this.width, this.height, this.colorFilter }) - : name = name, - super(key: new Key(name)); + AssetImage({ Key key, this.name, this.bundle, this.width, this.height, this.colorFilter }) : super(key: key); final String name; final AssetBundle bundle; diff --git a/packages/flutter/lib/widgets/icon_button.dart b/packages/flutter/lib/widgets/icon_button.dart index c63854f37f..fefe4cc07c 100644 --- a/packages/flutter/lib/widgets/icon_button.dart +++ b/packages/flutter/lib/widgets/icon_button.dart @@ -11,8 +11,7 @@ import 'package:sky/widgets/widget.dart'; class IconButton extends Component { - IconButton({ String icon: '', this.onPressed, this.color }) - : super(key: new Key(icon)), icon = icon; + IconButton({ Key key, this.icon, this.onPressed, this.color }) : super(key: key); final String icon; final Function onPressed; diff --git a/packages/flutter/lib/widgets/tabs.dart b/packages/flutter/lib/widgets/tabs.dart index 8de067c3e1..289fe28319 100644 --- a/packages/flutter/lib/widgets/tabs.dart +++ b/packages/flutter/lib/widgets/tabs.dart @@ -249,14 +249,14 @@ class RenderTabBar extends RenderBox with class TabBarWrapper extends MultiChildRenderObjectWrapper { TabBarWrapper({ + Key key, List children, this.selectedIndex, this.backgroundColor, this.indicatorColor, this.textAndIcons, this.scrollable: false, - this.onLayoutChanged, - Key key + this.onLayoutChanged }) : super(key: key, children: children); final int selectedIndex; @@ -378,13 +378,11 @@ class TabBar extends Scrollable { } Widget _toTab(TabLabel label, int tabIndex) { - Tab tab = new Tab( - label: label, - selected: tabIndex == selectedIndex, - key: new Key(label.text == null ? label.icon : label.text) - ); return new Listener( - child: tab, + child: new Tab( + label: label, + selected: tabIndex == selectedIndex + ), onGestureTap: (_) => _handleTap(tabIndex) ); }