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

Exit transition does not work when awaiting dialog future in VWidgetGuard.beforeLeave #191

Open
saibotma opened this issue Apr 24, 2022 · 0 comments

Comments

@saibotma
Copy link

Steps to reproduce:

  • Run the example below
  • Click on "to /home" and see the transition from bottom to top
  • Click on "to /"
  • Click apply on the dialog
  • Notice that the page closes, but not transition is displayed

It also does not work when you replace VWidgetGuard with WillPopScope.

Versions:

  • VRouter: 1.2.0+21
  • Flutter: 2.10.5
Code
import 'package:flutter/material.dart';
import 'package:vrouter/vrouter.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return VRouter(
      initialUrl: "/",
      routes: [
        VWidget(
          path: "/",
          widget: const Page(
            name: "/",
            color: Colors.red,
            routeTo: ["/home"],
          ),
          stackedRoutes: [
            VWidget.builder(
              path: "home",
              buildTransition: (animation, _, child) {
                return SlideTransition(
                  position: Tween<Offset>(
                    begin: const Offset(0.0, 1.0),
                    end: Offset.zero,
                  ).animate(animation),
                  child: child,
                );
              },
              builder: (context, data) {
                return VWidgetGuard(
                  beforeLeave: (_, __) async {
                    // The exit transition works when you just return.
                    //return;

                    // Exit transition does not work.
                    await showDialog<bool>(
                      context: context,
                      builder: (context) {
                        return AlertDialog(
                          title: const Text('AlertDialog Title'),
                          content: SingleChildScrollView(
                            child: ListBody(
                              children: const <Widget>[
                                Text('This is a demo alert dialog.'),
                                Text(
                                  'Would you like to approve of this message?',
                                ),
                              ],
                            ),
                          ),
                          actions: <Widget>[
                            TextButton(
                              child: const Text('Approve'),
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                            ),
                          ],
                        );
                      },
                    );
                  },
                  child: const Page(
                    name: "/home",
                    color: Colors.blue,
                    routeTo: ["/"],
                  ),
                );
              },
            ),
          ],
        ),
      ],
    );
  }
}

class Page extends StatelessWidget {
  final String name;
  final List<String> routeTo;
  final Color color;

  const Page({
    required this.name,
    this.routeTo = const [],
    required this.color,
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: color,
        alignment: Alignment.center,
        child: Column(
          children: [
            Text(
              name,
              style: const TextStyle(fontSize: 100),
            ),
            ...routeTo.map((e) {
              return ElevatedButton(
                onPressed: () => context.vRouter.to(e),
                child: Text("to $e"),
              );
            })
          ],
        ),
      ),
    );
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant