Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sky/sdk/lib/editing/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const EdgeDims _kTextfieldPadding = const EdgeDims.symmetric(vertical: 8.0);
class Input extends StatefulComponent {

Input({
Key key,
GlobalKey key,
this.placeholder,
this.onChanged
}): super(key: key);
Expand Down
2 changes: 1 addition & 1 deletion sky/sdk/lib/widgets/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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 Key, Widget, Component, StatefulComponent, App, runApp, Listener, ParentDataNode;
export 'package:sky/widgets/widget.dart' show Key, GlobalKey, Widget, Component, StatefulComponent, App, runApp, Listener, ParentDataNode;


// PAINTING NODES
Expand Down
4 changes: 2 additions & 2 deletions sky/sdk/lib/widgets/focus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Focus extends Inherited {

Focus({
GlobalKey key,
GlobalKey initialFocus,
this.initialFocus,
Widget child
}) : super(key: key, child: child);

GlobalKey initialFocus;
final GlobalKey initialFocus;

GlobalKey _currentlyFocusedKey;
GlobalKey get currentlyFocusedKey {
Expand Down
37 changes: 35 additions & 2 deletions sky/sdk/lib/widgets/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,46 @@ abstract class Widget {
_notifyingMountStatus = false;
sky.tracing.end("Widget._notifyMountStatusChanged");
}
assert(_debugDuplicateGlobalKeys.isEmpty);
}

static final Map<GlobalKey, Widget> _globalKeys = new Map<GlobalKey, Widget>();
static final Map<GlobalKey, int> _debugDuplicateGlobalKeys = new Map<GlobalKey, int>();

/// Override this function to learn when this [Widget] enters the widget tree.
void didMount() { }
void didMount() {
if (key is GlobalKey) {
assert(() {
if (_globalKeys.containsKey(key)) {
int oldCount = _debugDuplicateGlobalKeys.putIfAbsent(key, () => 1);
assert(oldCount >= 1);
_debugDuplicateGlobalKeys[key] = oldCount + 1;
}
return true;
});
_globalKeys[key] = this;
}
}

/// Override this function to learn when this [Widget] leaves the widget tree.
void didUnmount() { }
void didUnmount() {
if (key is GlobalKey) {
assert(() {
if (_globalKeys.containsKey(key) && _debugDuplicateGlobalKeys.containsKey(key)) {
int oldCount = _debugDuplicateGlobalKeys[key];
assert(oldCount >= 2);
if (oldCount == 2) {
_debugDuplicateGlobalKeys.remove(key);
} else {
_debugDuplicateGlobalKeys[key] = oldCount - 1;
}
}
return true;
});
if (_globalKeys[key] == this)
_globalKeys.remove(key);
}
}

RenderObject _root;

Expand Down