Skip to content

Commit

Permalink
Fixes marianocordoba#38: treat menu after rotation
Browse files Browse the repository at this point in the history
Using WidgetsBindingObserver's didChangeMetrics call _calculateProps and close.
I haven't tried what this does if the app is resized in a split screen mode, but this is certainly needed for rotation.
  • Loading branch information
MrCsabaToth authored Jul 14, 2022
1 parent 6aa6eb3 commit 32b9a0d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/fab_circular_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FabCircularMenu extends StatefulWidget {
}

class FabCircularMenuState extends State<FabCircularMenu>
with SingleTickerProviderStateMixin {
with SingleTickerProviderStateMixin, WidgetsBindingObserver {
late double _screenWidth;
late double _screenHeight;
late double _marginH;
Expand Down Expand Up @@ -85,6 +85,7 @@ class FabCircularMenuState extends State<FabCircularMenu>
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);

_animationController =
AnimationController(duration: widget.animationDuration, vsync: this);
Expand All @@ -111,9 +112,18 @@ class FabCircularMenuState extends State<FabCircularMenu>
@override
void dispose() {
_animationController.dispose();
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

@override
void didChangeMetrics() {
_calculateProps();
if (isOpen) {
close();
}
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
Expand Down

0 comments on commit 32b9a0d

Please sign in to comment.