Skip to content

Commit

Permalink
fix: dispose FocusNodes created via side effects
Browse files Browse the repository at this point in the history
Fixes #179
  • Loading branch information
GregoryConrad committed May 16, 2024
1 parent ac1adba commit b1a738f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/flutter_rearch/lib/src/side_effects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension BuiltinWidgetSideEffects on WidgetSideEffectRegistrar {
bool descendantsAreFocusable = true,
bool descendantsAreTraversable = true,
}) {
return use.callonce(FocusNode.new)
return use.disposable(FocusNode.new, (node) => node.dispose())
..debugLabel = debugLabel
// ignore: deprecated_member_use
..onKey = onKey
Expand All @@ -107,7 +107,7 @@ extension BuiltinWidgetSideEffects on WidgetSideEffectRegistrar {
TraversalEdgeBehavior traversalEdgeBehavior =
TraversalEdgeBehavior.closedLoop,
}) {
return use.callonce(FocusScopeNode.new)
return use.disposable(FocusScopeNode.new, (node) => node.dispose())
..debugLabel = debugLabel
// ignore: deprecated_member_use
..onKey = onKey
Expand All @@ -125,18 +125,16 @@ extension BuiltinWidgetSideEffects on WidgetSideEffectRegistrar {
void Function(ScrollPosition)? onAttach,
void Function(ScrollPosition)? onDetach,
}) {
final controller = use.memo(
return use.disposable(
() => PageController(
initialPage: initialPage,
keepPage: keepPage,
viewportFraction: viewportFraction,
onAttach: onAttach,
onDetach: onDetach,
),
(controller) => controller.dispose(),
[initialPage, keepPage, viewportFraction, onAttach, onDetach],
);
use.effect(() => controller.dispose, [controller]);

return controller;
}
}

0 comments on commit b1a738f

Please sign in to comment.