Home > Back-end >  How to close flutter speed dial when tap on a label widget?
How to close flutter speed dial when tap on a label widget?

Time:05-12

Is there a way to close the flutter speedDial when tap on a label widget?. I did not use SpeedDial's child property, but it has that feature. Currently when I tap on a label widget it stays until I manually close the widget. Or even a way to change the child property of SpeedDial widget would be enough, while I want a custom shape like in the picture.

Navigator.pop()  did not work

sample image

                      SpeedDial(
                                buttonSize: const Size(45, 45),
                                animatedIcon: AnimatedIcons.menu_close,
                                children: [
                                  SpeedDialChild(
                                    labelWidget: GestureDetector(
                                      onTap: () async {
                                        Feedback.forTap(context);
                                        await _crudStorage.deleteAllTask();
                                      },
                                      child: Container(
                                        height: 50.0,
                                        decoration: BoxDecoration(
                                          color:
                                              Theme.of(context).cardColor,
                                          border: Border.all(width: 2.0),
                                          borderRadius:
                                              BorderRadius.circular(30.0),
                                        ),
                                        child: Row(
                                          children: [
                                            const Padding(
                                              padding: EdgeInsets.only(
                                                  left: 12.0, right: 8.0),
                                              child:
                                                  Text('Clear all tasks'),
                                            ),
                                            Padding(
                                              padding:
                                                  const EdgeInsets.only(
                                                      right: 8.0),
                                              child: SvgPicture.asset(
                                                'assets/svg/all.svg',
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                ],
                              ) 

CodePudding user response:

don't use async & await on tap use separate function to Call

https://tutorialmeta.com/question/how-to-call-async-function-with-ontap-flutter

refer the above link

CodePudding user response:

It was so simple. Also the development team, provided how to implement this on their official extension page on pub.dev go to pub. I will mention the same documentation for your reference:

first you need to create a value notifier:

ValueNotifier<bool> isDialOpen = ValueNotifier(false);

Then set openCloseDial to isDialOpen in your SpeedDial:

SpeedDial(
  ...
  openCloseDial: isDialOpen,
  ...
)

Now you can change the state of dial open:

isDialOpen.value = false;

Example: Just set the value to false inside the onTap callback :)

 onTap: () async {
                   Feedback.forTap(context);
                   await _crudStorage.deleteAllTask();
                   isDialOpen.value = false;
                 },
  • Related