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

Using go_router .go() method to close a sheet don't seems to reset animation state #211

Open
glemartret opened this issue Aug 7, 2024 · 6 comments
Labels
bug Something isn't working P1
Milestone

Comments

@glemartret
Copy link

When I use .go() method from go router the current Sheet closes but the screen behind stays scaled down.

Quick exemple:

  1. currently on home page
  2. open a CupertinoSheet with go_router
  3. in the sheet, tap a button that does ".go(Home)"
  4. the sheet closes but the home page have black left, right and bottom borders

I'll complete this issue more precisely later.
If anyone have some infos to help on this, I'll be thankful

@fujidaiti
Copy link
Owner

fujidaiti commented Aug 10, 2024

Hi @glemartret,

I tried the following code, but couldn't reproduce the problem.
Can you fill in the missing part in the code to reproduce this issue?

Code
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:smooth_sheets/smooth_sheets.dart';

void main() {
  runApp(const _DeclarativeModalSheetExample());
}

final _router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) {
        return const _ExampleHome();
      },
      routes: [
        GoRoute(
          path: 'modal-sheet',
          pageBuilder: (context, state) {
            return CupertinoModalSheetPage(
              key: state.pageKey,
              swipeDismissible: true,
              child: const _ExampleSheet(),
            );
          },
        ),
      ],
    ),
  ],
);

class _DeclarativeModalSheetExample extends StatelessWidget {
  const _DeclarativeModalSheetExample();

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(routerConfig: _router);
  }
}

class _ExampleHome extends StatelessWidget {
  const _ExampleHome();

  @override
  Widget build(BuildContext context) {
    return CupertinoStackedTransition(
      child: Scaffold(
        body: Center(
          child: ElevatedButton(
            onPressed: () => context.go('/modal-sheet'),
            child: const Text('Show Modal Sheet'),
          ),
        ),
      ),
    );
  }
}

class _ExampleSheet extends StatelessWidget {
  const _ExampleSheet();

  @override
  Widget build(BuildContext context) {
    return DraggableSheet(
      child: Container(
        color: Colors.white,
        height: 800,
        width: double.infinity,
        alignment: Alignment.center,
        child: TextButton(
          onPressed: () => context.go('/'),
          child: const Text('Close Sheet'),
        ),
      ),
    );
  }
}

@fujidaiti fujidaiti added the need more information Lack of information to reproduce or determine if it is a bug or not label Aug 10, 2024
@fujidaiti
Copy link
Owner

fujidaiti commented Aug 10, 2024

the sheet closes but the home page have black left, right and bottom borders

I guess this is because the transition animation is not performed when the modal sheet closes. (I don't know why, though)

@glemartret
Copy link
Author

glemartret commented Oct 3, 2024

Hey @fujidaiti,
I have a sample to reproduce this behavior, but I don't know if this is a real issue then...

Code
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:smooth_sheets/smooth_sheets.dart';

void main() {
  runApp(const _DeclarativeModalSheetExample());
}

final _router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) {
        return const _ExampleHome();
      },
      routes: [
        GoRoute(
          path: 'modal-sheet',
          pageBuilder: (context, state) {
            return CupertinoModalSheetPage(
              key: state.pageKey,
              swipeDismissible: true,
              child: const _ExampleSheet(),
            );
          },
        ),
      ],
    ),
  ],
);

class _DeclarativeModalSheetExample extends StatelessWidget {
  const _DeclarativeModalSheetExample();

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(routerConfig: _router);
  }
}

class _ExampleHome extends StatelessWidget {
  const _ExampleHome();

  @override
  Widget build(BuildContext context) {
    return CupertinoStackedTransition(
      child: Scaffold(
        body: Center(
          child: ElevatedButton(
            onPressed: () => context.go('/modal-sheet'),
            child: const Text('Show Modal Sheet'),
          ),
        ),
      ),
    );
  }
}

class _ExampleSheet extends StatelessWidget {
  const _ExampleSheet();

  @override
  Widget build(BuildContext context) {
    return DraggableSheet(
      child: Container(
        color: Colors.white,
        height: 800,
        width: double.infinity,
        alignment: Alignment.center,
        child: TextButton(
          onPressed: () async {
            // INFO: Adding this line will cause the issue            <=====================
            showAboutDialog(context: context);

            context.go('/');
          },
          child: const Text('Close Sheet'),
        ),
      ),
    );
  }
}

@fujidaiti
Copy link
Owner

fujidaiti commented Oct 5, 2024

@glemartret What does showAboutDialog do? Does it push a new route?

@glemartret
Copy link
Author

@fujidaiti That's a Flutter function

@fujidaiti
Copy link
Owner

@glemartret

Thank you. Seeing the same issue as reported with the provided code.

@fujidaiti fujidaiti added bug Something isn't working P1 and removed need more information Lack of information to reproduce or determine if it is a bug or not in triage labels Oct 7, 2024
@fujidaiti fujidaiti added this to the stable milestone Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1
Projects
None yet
Development

No branches or pull requests

2 participants