Skip to content

Commit

Permalink
Remove overlay on page change (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbendebiene authored Apr 3, 2024
1 parent 93d76ab commit 4e4b1fd
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions lib/freestyle_speed_dial.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,9 @@ class _SpeedDialBuilderState<T> extends State<SpeedDialBuilder<T>>

final _buttonLayerLink = LayerLink();

late final _controller = AnimationController(vsync: this);
final _overlayPortalController = OverlayPortalController();

late final _overlayEntry = OverlayEntry(
builder: _overlayEntryBuilder,
);
late final _controller = AnimationController(vsync: this);

@override
void initState() {
Expand All @@ -194,7 +192,7 @@ class _SpeedDialBuilderState<T> extends State<SpeedDialBuilder<T>>
setState(() {
if (status == AnimationStatus.dismissed) {
// remove overlay / hide speed dial buttons
_overlayEntry.remove();
_overlayPortalController.hide();
}
});
});
Expand All @@ -205,10 +203,6 @@ class _SpeedDialBuilderState<T> extends State<SpeedDialBuilder<T>>
super.didUpdateWidget(oldWidget);

_calcAnimationValues();

WidgetsBinding.instance.addPostFrameCallback(
(_) => _overlayEntry.markNeedsBuild(),
);
}

// trigger overlay rebuild on hot reload
Expand All @@ -217,8 +211,6 @@ class _SpeedDialBuilderState<T> extends State<SpeedDialBuilder<T>>
super.reassemble();

_calcAnimationValues();

_overlayEntry.markNeedsBuild();
}

// pre calculate necessary variables
Expand Down Expand Up @@ -307,9 +299,13 @@ class _SpeedDialBuilderState<T> extends State<SpeedDialBuilder<T>>

@override
Widget build(BuildContext context) {
return CompositedTransformTarget(
link: _buttonLayerLink,
child: widget.buttonBuilder(context, isActive, toggle),
return OverlayPortal(
controller: _overlayPortalController,
overlayChildBuilder: _overlayEntryBuilder,
child: CompositedTransformTarget(
link: _buttonLayerLink,
child: widget.buttonBuilder(context, isActive, toggle),
),
);
}

Expand All @@ -323,7 +319,7 @@ class _SpeedDialBuilderState<T> extends State<SpeedDialBuilder<T>>
void toggle() {
if (_controller.isDismissed) {
Overlay.of(context)?.insert(_overlayEntry);
_overlayPortalController.show();
_controller.forward();
} else {
_controller.reverse();
Expand All @@ -338,17 +334,9 @@ class _SpeedDialBuilderState<T> extends State<SpeedDialBuilder<T>>
}
}



@override
void dispose() {
_controller.dispose();

if (_overlayEntry.mounted) {
_overlayEntry.remove();
}
_overlayEntry.dispose();

super.dispose();
}
}

0 comments on commit 4e4b1fd

Please sign in to comment.