Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close self OverlayEntry onTap

Tags:

flutter

dart

I have an OverlayEntry that displays fullscreen. I want to dispatch an actions an close it onTap of the overlayentry's buttons

OverlayEntry _buildOverlayFeedback(BuildContext context, String tituloEvento) {
      return OverlayEntry(
        builder: (context) => Material(
          child: Container(
            width: double.infinity,
            height: double.infinity,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Column(
                  children: <Widget>[
                    ListTile(
                      leading: Icon(Icons.sentiment_dissatisfied),
                      title: Text('No me ha gustado'),
                      onTap: () {
                            // how to close myself????
                      },
                    ),
                    ListTile(
                        leading: Icon(Icons.sentiment_very_satisfied),
                        title: Text('Muy bien'),
                        onTap: () {}),
                  ],
                ),
              ],
            ),
          ),
        ),
      );
    }
like image 201
user3712489 Avatar asked Oct 29 '25 14:10

user3712489


1 Answers

You call remove() on the OverlayEntry itself.

This could be one way of doing it:

      OverlayEntry _buildOverlayFeedback(BuildContext context, String tituloEvento) {
        OverlayEntry? entry;
        entry = OverlayEntry(
          builder: (context) => Material(
            child: Container(
              width: double.infinity,
              height: double.infinity,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Column(
                    children: <Widget>[
                      ListTile(
                        leading: Icon(Icons.sentiment_dissatisfied),
                        title: Text('No me ha gustado'),
                        onTap: () {
                          entry!.remove();
                        },
                      ),
                      ListTile(
                          leading: Icon(Icons.sentiment_very_satisfied),
                          title: Text('Muy bien'),
                          onTap: () {}),
                    ],
                  ),
                ],
              ),
            ),
          ),
        );
        return entry!;
      }
like image 102
chemamolins Avatar answered Oct 31 '25 12:10

chemamolins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!