I am using the flutter speed dial package to implement expandable FAB.
It is working fine. The only problem I have is that when I press on the back button with the speed dial open, it closes (puts it the background) and when I open the app again the speed dial is still open.
I would like the speed dial to close when I press on the back button without closing the app.
I have tried using PopScope without success as oppose to WillPopScope which is used in the example page of the package.
return SpeedDial(
activeIcon: Icons.close_rounded,
backgroundColor: theme.colorScheme.primary,
foregroundColor: theme.colorScheme.primary,
overlayColor: Colors.black,
overlayOpacity: 0.6,
spaceBetweenChildren: 16,
iconTheme: const IconThemeData(color: Colors.white),
icon: Icons.add_rounded,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(Sizes.sixteen))),
children: [
2
Answers
Checkout the
openCloseDial
property in SpeedDial.You can create a value notifier and assign it to the property and handle it in the WillPopScope.
In your PopScope, you can do this:
If you are using Go_Router keep in mind that PopScope wont’t work instead you can use BackButtonListener
https://api.flutter.dev/flutter/widgets/BackButtonListener-class.html
Use Example: