Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename _*Marker classes to be _*Scope, for consistency #118070

Merged
merged 3 commits into from Jan 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/flutter/lib/src/material/menu_anchor.dart
Expand Up @@ -362,7 +362,7 @@ class _MenuAnchorState extends State<MenuAnchor> {
);
}

return _MenuAnchorMarker(
return _MenuAnchorScope(
anchorKey: _anchorKey,
anchor: this,
isOpen: _isOpen,
Expand Down Expand Up @@ -511,7 +511,7 @@ class _MenuAnchorState extends State<MenuAnchor> {
// Copy all the themes from the supplied outer context to the
// overlay.
outerContext,
_MenuAnchorMarker(
_MenuAnchorScope(
// Re-advertize the anchor here in the overlay, since
// otherwise a search for the anchor by descendants won't find
// it.
Expand Down Expand Up @@ -571,7 +571,7 @@ class _MenuAnchorState extends State<MenuAnchor> {
// dependency relationship that will rebuild the context when the node
// changes.
static _MenuAnchorState? _maybeOf(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<_MenuAnchorMarker>()?.anchor;
return context.dependOnInheritedWidgetOfExactType<_MenuAnchorScope>()?.anchor;
}
}

Expand Down Expand Up @@ -2195,8 +2195,8 @@ class _LocalizedShortcutLabeler {
}
}

class _MenuAnchorMarker extends InheritedWidget {
const _MenuAnchorMarker({
class _MenuAnchorScope extends InheritedWidget {
const _MenuAnchorScope({
required super.child,
required this.anchorKey,
required this.anchor,
Expand All @@ -2208,7 +2208,7 @@ class _MenuAnchorMarker extends InheritedWidget {
final bool isOpen;

@override
bool updateShouldNotify(_MenuAnchorMarker oldWidget) {
bool updateShouldNotify(_MenuAnchorScope oldWidget) {
return anchorKey != oldWidget.anchorKey
|| anchor != oldWidget.anchor
|| isOpen != oldWidget.isOpen;
Expand Down
28 changes: 14 additions & 14 deletions packages/flutter/lib/src/widgets/actions.dart
Expand Up @@ -662,7 +662,7 @@ class Actions extends StatefulWidget {
// getElementForInheritedWidgetOfExactType. Returns true if the visitor found
// what it was looking for.
static bool _visitActionsAncestors(BuildContext context, bool Function(InheritedElement element) visitor) {
InheritedElement? actionsElement = context.getElementForInheritedWidgetOfExactType<_ActionsMarker>();
InheritedElement? actionsElement = context.getElementForInheritedWidgetOfExactType<_ActionsScope>();
while (actionsElement != null) {
if (visitor(actionsElement) == true) {
break;
Expand All @@ -671,7 +671,7 @@ class Actions extends StatefulWidget {
// context.getElementForInheritedWidgetOfExactType will return itself if it
// happens to be of the correct type.
final BuildContext parent = _getParent(actionsElement);
actionsElement = parent.getElementForInheritedWidgetOfExactType<_ActionsMarker>();
actionsElement = parent.getElementForInheritedWidgetOfExactType<_ActionsScope>();
}
return actionsElement != null;
}
Expand All @@ -681,7 +681,7 @@ class Actions extends StatefulWidget {
static ActionDispatcher _findDispatcher(BuildContext context) {
ActionDispatcher? dispatcher;
_visitActionsAncestors(context, (InheritedElement element) {
final ActionDispatcher? found = (element.widget as _ActionsMarker).dispatcher;
final ActionDispatcher? found = (element.widget as _ActionsScope).dispatcher;
if (found != null) {
dispatcher = found;
return true;
Expand Down Expand Up @@ -788,7 +788,7 @@ class Actions extends StatefulWidget {
);

_visitActionsAncestors(context, (InheritedElement element) {
final _ActionsMarker actions = element.widget as _ActionsMarker;
final _ActionsScope actions = element.widget as _ActionsScope;
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null) {
context.dependOnInheritedElement(element);
Expand Down Expand Up @@ -817,7 +817,7 @@ class Actions extends StatefulWidget {
);

_visitActionsAncestors(context, (InheritedElement element) {
final _ActionsMarker actions = element.widget as _ActionsMarker;
final _ActionsScope actions = element.widget as _ActionsScope;
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null) {
action = result;
Expand All @@ -830,8 +830,8 @@ class Actions extends StatefulWidget {
}

// Find the [Action] that handles the given `intent` in the given
// `_ActionsMarker`, and verify it has the right type parameter.
static Action<T>? _castAction<T extends Intent>(_ActionsMarker actionsMarker, { T? intent }) {
// `_ActionsScope`, and verify it has the right type parameter.
static Action<T>? _castAction<T extends Intent>(_ActionsScope actionsMarker, { T? intent }) {
final Action<Intent>? mappedAction = actionsMarker.actions[intent?.runtimeType ?? T];
if (mappedAction is Action<T>?) {
return mappedAction;
Expand All @@ -851,7 +851,7 @@ class Actions extends StatefulWidget {
/// widget is found.
static ActionDispatcher of(BuildContext context) {
assert(context != null);
final _ActionsMarker? marker = context.dependOnInheritedWidgetOfExactType<_ActionsMarker>();
final _ActionsScope? marker = context.dependOnInheritedWidgetOfExactType<_ActionsScope>();
return marker?.dispatcher ?? _findDispatcher(context);
}

Expand All @@ -878,7 +878,7 @@ class Actions extends StatefulWidget {
Object? returnValue;

final bool actionFound = _visitActionsAncestors(context, (InheritedElement element) {
final _ActionsMarker actions = element.widget as _ActionsMarker;
final _ActionsScope actions = element.widget as _ActionsScope;
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null && result.isEnabled(intent)) {
// Invoke the action we found using the relevant dispatcher from the Actions
Expand Down Expand Up @@ -931,7 +931,7 @@ class Actions extends StatefulWidget {
Object? returnValue;

_visitActionsAncestors(context, (InheritedElement element) {
final _ActionsMarker actions = element.widget as _ActionsMarker;
final _ActionsScope actions = element.widget as _ActionsScope;
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null && result.isEnabled(intent)) {
// Invoke the action we found using the relevant dispatcher from the Actions
Expand Down Expand Up @@ -1005,7 +1005,7 @@ class _ActionsState extends State<Actions> {

@override
Widget build(BuildContext context) {
return _ActionsMarker(
return _ActionsScope(
actions: widget.actions,
dispatcher: widget.dispatcher,
rebuildKey: rebuildKey,
Expand All @@ -1016,8 +1016,8 @@ class _ActionsState extends State<Actions> {

// An inherited widget used by Actions widget for fast lookup of the Actions
// widget information.
class _ActionsMarker extends InheritedWidget {
const _ActionsMarker({
class _ActionsScope extends InheritedWidget {
const _ActionsScope({
required this.dispatcher,
required this.actions,
required this.rebuildKey,
Expand All @@ -1030,7 +1030,7 @@ class _ActionsMarker extends InheritedWidget {
final Object rebuildKey;

@override
bool updateShouldNotify(_ActionsMarker oldWidget) {
bool updateShouldNotify(_ActionsScope oldWidget) {
return rebuildKey != oldWidget.rebuildKey
|| oldWidget.dispatcher != dispatcher
|| !mapEquals<Type, Action<Intent>>(oldWidget.actions, actions);
Expand Down
16 changes: 8 additions & 8 deletions packages/flutter/lib/src/widgets/focus_scope.dart
Expand Up @@ -388,7 +388,7 @@ class Focus extends StatefulWidget {
static FocusNode of(BuildContext context, { bool scopeOk = false }) {
assert(context != null);
assert(scopeOk != null);
final _FocusMarker? marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>();
final _FocusInheritedScope? marker = context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>();
final FocusNode? node = marker?.notifier;
assert(() {
if (node == null) {
Expand Down Expand Up @@ -440,7 +440,7 @@ class Focus extends StatefulWidget {
static FocusNode? maybeOf(BuildContext context, { bool scopeOk = false }) {
assert(context != null);
assert(scopeOk != null);
final _FocusMarker? marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>();
final _FocusInheritedScope? marker = context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>();
final FocusNode? node = marker?.notifier;
if (node == null) {
return null;
Expand Down Expand Up @@ -686,7 +686,7 @@ class _FocusState extends State<Focus> {
child: widget.child,
);
}
return _FocusMarker(
return _FocusInheritedScope(
node: focusNode,
child: child,
);
Expand Down Expand Up @@ -798,7 +798,7 @@ class FocusScope extends Focus {
/// The [context] argument must not be null.
static FocusScopeNode of(BuildContext context) {
assert(context != null);
final _FocusMarker? marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>();
final _FocusInheritedScope? marker = context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>();
return marker?.notifier?.nearestScope ?? context.owner!.focusManager.rootScope;
}

Expand Down Expand Up @@ -853,17 +853,17 @@ class _FocusScopeState extends _FocusState {
_focusAttachment!.reparent(parent: widget.parentNode);
return Semantics(
explicitChildNodes: true,
child: _FocusMarker(
child: _FocusInheritedScope(
node: focusNode,
child: widget.child,
),
);
}
}

// The InheritedWidget marker for Focus and FocusScope.
class _FocusMarker extends InheritedNotifier<FocusNode> {
const _FocusMarker({
// The InheritedWidget for Focus and FocusScope.
class _FocusInheritedScope extends InheritedNotifier<FocusNode> {
const _FocusInheritedScope({
required FocusNode node,
required super.child,
}) : assert(node != null),
Expand Down
22 changes: 11 additions & 11 deletions packages/flutter/lib/src/widgets/focus_traversal.dart
Expand Up @@ -47,7 +47,7 @@ void _focusAndEnsureVisible(
// sorting their contents.
class _FocusTraversalGroupInfo {
_FocusTraversalGroupInfo(
_FocusTraversalGroupMarker? marker, {
_FocusTraversalGroupScope? marker, {
FocusTraversalPolicy? defaultPolicy,
List<FocusNode>? members,
}) : groupNode = marker?.focusNode,
Expand Down Expand Up @@ -284,20 +284,20 @@ abstract class FocusTraversalPolicy with Diagnosticable {
@protected
Iterable<FocusNode> sortDescendants(Iterable<FocusNode> descendants, FocusNode currentNode);

_FocusTraversalGroupMarker? _getMarker(BuildContext? context) {
return context?.getElementForInheritedWidgetOfExactType<_FocusTraversalGroupMarker>()?.widget as _FocusTraversalGroupMarker?;
_FocusTraversalGroupScope? _getMarker(BuildContext? context) {
return context?.getElementForInheritedWidgetOfExactType<_FocusTraversalGroupScope>()?.widget as _FocusTraversalGroupScope?;
}

// Sort all descendants, taking into account the FocusTraversalGroup
// that they are each in, and filtering out non-traversable/focusable nodes.
List<FocusNode> _sortAllDescendants(FocusScopeNode scope, FocusNode currentNode) {
assert(scope != null);
final _FocusTraversalGroupMarker? scopeGroupMarker = _getMarker(scope.context);
final _FocusTraversalGroupScope? scopeGroupMarker = _getMarker(scope.context);
final FocusTraversalPolicy defaultPolicy = scopeGroupMarker?.policy ?? ReadingOrderTraversalPolicy();
// Build the sorting data structure, separating descendants into groups.
final Map<FocusNode?, _FocusTraversalGroupInfo> groups = <FocusNode?, _FocusTraversalGroupInfo>{};
for (final FocusNode node in scope.descendants) {
final _FocusTraversalGroupMarker? groupMarker = _getMarker(node.context);
final _FocusTraversalGroupScope? groupMarker = _getMarker(node.context);
final FocusNode? groupNode = groupMarker?.focusNode;
// Group nodes need to be added to their parent's node, or to the "null"
// node if no parent is found. This creates the hierarchy of group nodes
Expand All @@ -309,7 +309,7 @@ abstract class FocusTraversalPolicy with Diagnosticable {
// looking with that node's parent, since _getMarker will return the
// context it was called on if it matches the type.
final BuildContext? parentContext = _getAncestor(groupNode!.context!, count: 2);
final _FocusTraversalGroupMarker? parentMarker = _getMarker(parentContext);
final _FocusTraversalGroupScope? parentMarker = _getMarker(parentContext);
final FocusNode? parentNode = parentMarker?.focusNode;
groups[parentNode] ??= _FocusTraversalGroupInfo(parentMarker, members: <FocusNode>[], defaultPolicy: defaultPolicy);
assert(!groups[parentNode]!.members.contains(node));
Expand Down Expand Up @@ -1539,7 +1539,7 @@ class FocusTraversalGroup extends StatefulWidget {
/// [FocusTraversalGroup] ancestor is found.
static FocusTraversalPolicy of(BuildContext context) {
assert(context != null);
final _FocusTraversalGroupMarker? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupMarker>();
final _FocusTraversalGroupScope? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupScope>();
assert(() {
if (inherited == null) {
throw FlutterError(
Expand Down Expand Up @@ -1574,7 +1574,7 @@ class FocusTraversalGroup extends StatefulWidget {
/// ancestor is found.
static FocusTraversalPolicy? maybeOf(BuildContext context) {
assert(context != null);
final _FocusTraversalGroupMarker? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupMarker>();
final _FocusTraversalGroupScope? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupScope>();
return inherited?.policy;
}

Expand Down Expand Up @@ -1612,7 +1612,7 @@ class _FocusTraversalGroupState extends State<FocusTraversalGroup> {

@override
Widget build(BuildContext context) {
return _FocusTraversalGroupMarker(
return _FocusTraversalGroupScope(
policy: widget.policy,
focusNode: focusNode!,
child: Focus(
Expand All @@ -1629,8 +1629,8 @@ class _FocusTraversalGroupState extends State<FocusTraversalGroup> {
}

// A "marker" inherited widget to make the group faster to find.
class _FocusTraversalGroupMarker extends InheritedWidget {
const _FocusTraversalGroupMarker({
class _FocusTraversalGroupScope extends InheritedWidget {
const _FocusTraversalGroupScope({
required this.policy,
required this.focusNode,
required super.child,
Expand Down
16 changes: 8 additions & 8 deletions packages/flutter/lib/src/widgets/shortcuts.dart
Expand Up @@ -1279,8 +1279,8 @@ class ShortcutRegistry with ChangeNotifier {
/// it doesn't find a [ShortcutRegistrar] ancestor.
static ShortcutRegistry of(BuildContext context) {
assert(context != null);
final _ShortcutRegistrarMarker? inherited =
context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarMarker>();
final _ShortcutRegistrarScope? inherited =
context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarScope>();
assert(() {
if (inherited == null) {
throw FlutterError(
Expand Down Expand Up @@ -1315,8 +1315,8 @@ class ShortcutRegistry with ChangeNotifier {
/// [ShortcutRegistrar] ancestor.
static ShortcutRegistry? maybeOf(BuildContext context) {
assert(context != null);
final _ShortcutRegistrarMarker? inherited =
context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarMarker>();
final _ShortcutRegistrarScope? inherited =
context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarScope>();
return inherited?.registry;
}

Expand Down Expand Up @@ -1433,7 +1433,7 @@ class _ShortcutRegistrarState extends State<ShortcutRegistrar> {

@override
Widget build(BuildContext context) {
return _ShortcutRegistrarMarker(
return _ShortcutRegistrarScope(
registry: registry,
child: Shortcuts.manager(
manager: manager,
Expand All @@ -1443,16 +1443,16 @@ class _ShortcutRegistrarState extends State<ShortcutRegistrar> {
}
}

class _ShortcutRegistrarMarker extends InheritedWidget {
const _ShortcutRegistrarMarker({
class _ShortcutRegistrarScope extends InheritedWidget {
const _ShortcutRegistrarScope({
required this.registry,
required super.child,
});

final ShortcutRegistry registry;

@override
bool updateShouldNotify(covariant _ShortcutRegistrarMarker oldWidget) {
bool updateShouldNotify(covariant _ShortcutRegistrarScope oldWidget) {
return registry != oldWidget.registry;
}
}