您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
65 行
2.1 KiB
65 行
2.1 KiB
using Unity.UIWidgets.foundation;
|
|
|
|
namespace Unity.UIWidgets.widgets {
|
|
class _FocusScopeMarker : InheritedWidget {
|
|
public _FocusScopeMarker(FocusScopeNode node, Widget child, Key key = null) : base(key, child) {
|
|
D.assert(node != null);
|
|
this.node = node;
|
|
}
|
|
|
|
public readonly FocusScopeNode node;
|
|
|
|
public override bool updateShouldNotify(InheritedWidget oldWidget) {
|
|
return this.node != ((_FocusScopeMarker) oldWidget).node;
|
|
}
|
|
}
|
|
|
|
public class FocusScope : StatefulWidget {
|
|
public FocusScope(FocusScopeNode node, Widget child, Key key = null, bool autofocus = false) : base(key) {
|
|
this.node = node;
|
|
this.child = child;
|
|
this.autofocus = autofocus;
|
|
}
|
|
|
|
public readonly FocusScopeNode node;
|
|
|
|
public readonly bool autofocus;
|
|
|
|
public readonly Widget child;
|
|
|
|
public static FocusScopeNode of(BuildContext context) {
|
|
var scope = (_FocusScopeMarker) context.inheritFromWidgetOfExactType(typeof(_FocusScopeMarker));
|
|
if (scope != null && scope.node != null) {
|
|
return scope.node;
|
|
}
|
|
|
|
return context.owner.focusManager.rootScope;
|
|
}
|
|
|
|
public override State createState() {
|
|
return new _FocusScopeState();
|
|
}
|
|
}
|
|
|
|
class _FocusScopeState : State<FocusScope> {
|
|
bool _didAutofocus = false;
|
|
|
|
public override void didChangeDependencies() {
|
|
base.didChangeDependencies();
|
|
if (!this._didAutofocus && this.widget.autofocus) {
|
|
FocusScope.of(this.context).setFirstFocus(this.widget.node);
|
|
this._didAutofocus = true;
|
|
}
|
|
}
|
|
|
|
public override void dispose() {
|
|
this.widget.node.detach();
|
|
base.dispose();
|
|
}
|
|
|
|
public override Widget build(BuildContext context) {
|
|
FocusScope.of(context).reparentScopeIfNeeded(this.widget.node);
|
|
return new _FocusScopeMarker(node: this.widget.node, child: this.widget.child);
|
|
}
|
|
}
|
|
}
|