Skip to content

Commit

Permalink
fix: use maybeOf for AFFocusManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin committed Jun 2, 2024
1 parent ac7906e commit 48a545c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
return;
}

focusManager = AFFocusManager.of(context);
focusManager = AFFocusManager.maybeOf(context);
focusManager!.loseFocusNotifier.addListener(_loseFocus);

if (widget.initialSelection != null) {
Expand All @@ -273,11 +273,11 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {

@override
void didChangeDependencies() {
final currFocusManager = AFFocusManager.of(context);
final currFocusManager = AFFocusManager.maybeOf(context);
if (focusManager != currFocusManager) {
focusManager?.loseFocusNotifier.removeListener(_loseFocus);
focusManager = currFocusManager;
focusManager!.loseFocusNotifier.addListener(_loseFocus);
focusManager?.loseFocusNotifier.addListener(_loseFocus);
}
super.didChangeDependencies();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ class AFFocusManager extends InheritedWidget {
assert(result != null, "AFFocusManager could not be found");
return result!;
}

static AFFocusManager? maybeOf(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<AFFocusManager>();
}
}

0 comments on commit 48a545c

Please sign in to comment.