flutter_speed_dial
flutter_speed_dial copied to clipboard
Overlay remains if Navigator.push is called immediately after opening SpeedDial
Run the code below. If the Next page button is pressed immediately after opening SpeedDial, it becomes uncontrollable.
Example
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
void main() =>
runApp(const MaterialApp(title: "Speed Dial", home: MyHomePage()));
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Speed Dial")),
backgroundColor: Colors.black,
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const NextPage()),
);
},
child: const Text('Next page'),
),
),
floatingActionButton: SpeedDial(
children: [
SpeedDialChild(
child: const Icon(Icons.accessibility),
backgroundColor: Colors.red,
),
],
),
);
}
}
class NextPage extends StatelessWidget {
const NextPage({super.key});
@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
child: Scaffold(
backgroundColor: Colors.black,
body: Center(
child: ElevatedButton(
onPressed: () => Navigator.pop(context),
child: const Text("back"),
),
),
),
);
}
}
+1 Similar case, I'm not navigating after but the overlay persists after an option is selected. Weirdly enough it only happens on a physical device, everything works fine on the emulator (iOS).
I had a similar situation. Was able to resolve by using the OpenCloseDial property, and adding the following line to close the speed dial prior to navigating to another page:
isDialOpen.value = false;
See more info: https://github.com/darioielardi/flutter_speed_dial/blob/6608449829223c95752c93c8cabbc40730ebd72b/README.md?plain=1#L88
Hope that helps someone!
You can use RouteAware mixin on MyHomePage. It contains didPush(), didPushNext(), didPopNext() methods.