Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: How to make a dialog swipeable? #21

Closed
1 task done
Apollo108 opened this issue Aug 31, 2023 · 8 comments
Closed
1 task done

[Question]: How to make a dialog swipeable? #21

Apollo108 opened this issue Aug 31, 2023 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@Apollo108
Copy link

What is your question?

I'm trying to make a snackbar with 3 sec auto hide, + I need it to be able to swipe it away at any time. Didn't find a way to do this, please, help.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Apollo108 Apollo108 added the question Further information is requested label Aug 31, 2023
@feduke-nukem
Copy link
Owner

What is your question?

I'm trying to make a snackbar with 3 sec auto hide, + I need it to be able to swipe it away at any time. Didn't find a way to do this, please, help.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Hello @Apollo108.

import 'package:flutter/material.dart';
import 'package:flutter_easy_dialogs/flutter_easy_dialogs.dart';

void main() => runApp(const MainApp());

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: FlutterEasyDialogs.builder(),
      home: Scaffold(
        body: const Center(
          child: Text('Hello World!'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () => Container(
            color: Colors.red,
            height: 200,
            width: double.infinity,
          )
              .positioned(autoHideDuration: const Duration(seconds: 3))
              .swipe()
              .slideHorizontal()
              .show(),
        ),
      ),
    );
  }
}

Try this

@Apollo108
Copy link
Author

Apollo108 commented Sep 1, 2023

Thanks. But I also need to bind onHide and onShow callbacks, I found it possible via EasyDialogDecoration.builder, but I noticed that onHide doesn't trigger when I'm swiping it out, but the onDismiss does, so, in the end, it's working like this:
image

Please, correct me, if I'm doing it wrong.

@Apollo108
Copy link
Author

Apollo108 commented Sep 1, 2023

Also I need the onTap callback, but I didn't find anything similar. Can I avoid wrapping it in GestureDetector?)

@feduke-nukem
Copy link
Owner

Thanks. But I also need to bind onHide and onShow callbacks, I found it possible via EasyDialogDecoration.builder, but I noticed that onHide doesn't trigger when I'm swiping it out, but the onDismiss does, so, in the end, it's working like this: image

Please, correct me, if I'm doing it wrong.

You may use onHidden callback that is called when dialog is no longer presented. onHide doesn't fire in your case, because it's being removed via Dismissible which has it's own animation and lifecycle.

Also I need the onTap callback, but I didn't find anything similar. Can I avoid wrapping it in GestureDetector?)

You can add .tap() decoration:

import 'package:flutter/material.dart';
import 'package:flutter_easy_dialogs/flutter_easy_dialogs.dart';

void main() => runApp(const MainApp());

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: FlutterEasyDialogs.builder(),
      home: Scaffold(
        body: const Center(
          child: Text('Hello World!'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () => Container(
            color: Colors.red,
            height: 200,
            width: double.infinity,
          )
              .positioned(autoHideDuration: const Duration(seconds: 3))
              .swipe()
              .tap(
                onDismissed: () => print('tapped'),
              )
              .slideHorizontal()
              .decorate(
                EasyDialogDecoration.builder(
                  (context, dialog) => dialog.content,
                  onHidden: () {
                    print('');
                  },
                ),
              )
              .show(),
        ),
      ),
    );
  }
}

But it will also trigger dialog hiding, if you only need to recognize tap gestures, consider using GestureDetector on provided widget.

@Apollo108
Copy link
Author

Also, I noticed strange behavior for top-positioned dialogs - I have to add direction: position == EasyDialogPosition.top ? VerticalSlideDirection.down : VerticalSlideDirection.up, otherwise it will be sliding from the bottom (by default) during the appearance and hiding, and it looks weird. For bottom-positioned - it's fine

@feduke-nukem
Copy link
Owner

feduke-nukem commented Sep 1, 2023

Also, I noticed strange behavior for top-positioned dialogs - I have to add direction: position == EasyDialogPosition.top ? VerticalSlideDirection.down : VerticalSlideDirection.up, otherwise it will be sliding from the bottom (by default) during the appearance and hiding, and it looks weird. For bottom-positioned - it's fine

You have full control over your dialogs, that's it.

If you want the dialog slide from bot to top or vice versa then you should provide relevant parameters.

There's no dependency on dialog's position. As you could apply slideVertical decoration to full screen dialog also.

@Apollo108
Copy link
Author

Thank you for the awesome package and rapid response!

@feduke-nukem
Copy link
Owner

Thank you for the awesome package and rapid response!

You are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants