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

Navigate and other functions are way slower then they should be #1982

Open
Vildnex opened this issue Jun 20, 2024 · 8 comments
Open

Navigate and other functions are way slower then they should be #1982

Vildnex opened this issue Jun 20, 2024 · 8 comments

Comments

@Vildnex
Copy link

Vildnex commented Jun 20, 2024

I made a small project in order to demonstrate this bug which can be found here https://github.com/Vildnex/test_bug/tree/master

I have to 2 RoutePage which are PageA and PageB and an another RoutePage whihc is InitialPage:

Page A:

import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:test_bug/app_router.gr.dart';

@RoutePage()
class PageA extends StatelessWidget {
  const PageA({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.red.withOpacity(0.5),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            AutoRouter.of(context).navigate(const InitialRoute());
          },
          child: const Text('Go BACK'),
        ),
      ),
    );
  }
}

Page B:

import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:test_bug/app_router.gr.dart';

@RoutePage()
class PageB extends StatelessWidget {
  const PageB({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.blue.withOpacity(0.5),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            // AutoRouter.of(context).maybePopTop();
            // AutoRouter.of(context).navigate(const InitialRoute());
            AutoRouter.of(context).push(const InitialRoute());
          },
          child: const Text('Go BACK'),
        ),
      ),
    );
  }
}

Initial Page:

import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:test_bug/app_router.gr.dart';

@RoutePage()
class InitialPage extends StatelessWidget {
  const InitialPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Initial Page'),
      ),
      body: Column(
        children: [
          IgnorePointer(
            child: Align(
              alignment: Alignment.topCenter,
              child: SvgPicture.asset(
                "assets/machine-vision-svgrepo-com.svg",
                height: 500, // Adjusted height to fit within available space
              ),
            ),
          ),
          ElevatedButton(
            onPressed: () {
              AutoRouter.of(context).push(const RouteB());
            },
            child: const Text('Go to Page B'),
          ),
          ElevatedButton(
            onPressed: () {
              AutoRouter.of(context).push(const RouteA());
            },
            child: const Text('Go to Page A'),
          ),
        ],
      ),
    );
  }
}

I used CustomRoute with noTransition and a 1 milliseconds duration

App Router:

import 'package:auto_route/auto_route.dart' show AutoRoute, AutoRouterConfig, CustomRoute, TransitionsBuilders;
import 'package:flutter/material.dart';
import 'package:test_bug/app_router.gr.dart';

const int duration = 1;
const RouteTransitionsBuilder transition = TransitionsBuilders.noTransition;

@AutoRouterConfig()
class AppRouter extends $AppRouter {
  @override
  List<AutoRoute> get routes => [
        CustomRoute(
          page: RouteA.page,
          path: '/a',
          durationInMilliseconds: duration,
          transitionsBuilder: transition,
        ),
        CustomRoute(
          page: RouteB.page,
          path: '/b',
          durationInMilliseconds: duration,
          transitionsBuilder: transition,
        ),
        CustomRoute(
          page: InitialRoute.page,
          path: '/',
          durationInMilliseconds: duration,
          transitionsBuilder: transition,
        ),
      ];
}

If I will press the button to go to Page A or Page B, it is going to be instant. From page B where I used push going to the initial page is going to be instant. But on Page A where I used navigate (same problem if I use maybePopTop) then all the transitions will be WAY SLOWER.
Is this a bug? Or why the navigate and maybePopTop are WAY SLOWER than the push function, or am I missing something in the configuration part?

Screencast.from.2024-06-20.13-16-47.webm
@Vildnex
Copy link
Author

Vildnex commented Jun 20, 2024

Update:

After I've tested most of the navigation functions I faced the same issue for the following:

All of the following are SLOW:

  • AutoRouter.of(context).maybePopTop();
  • AutoRouter.of(context).maybePop();
  • AutoRouter.of(context).navigate(const InitialRoute());
  • AutoRouter.of(context).back();
  • AutoRouter.of(context).removeLast();
  • AutoRouter.of(context).popForced();

The other ones which are below are FASTER as they should be:

  • AutoRouter.of(context).replace(const InitialRoute());
  • AutoRouter.of(context).popAndPush(const InitialRoute());

@Vildnex Vildnex changed the title navigate is way slower then it should Navigate and other functions are way slower then they should be Jun 20, 2024
@Milad-Akarie
Copy link
Owner

@vaind try setting the reverse animation duration to zero

@Vildnex
Copy link
Author

Vildnex commented Jul 16, 2024

Hey,

Any update on this bug? @Milad-Akarie

@vad-bal
Copy link

vad-bal commented Jul 21, 2024

Hi @Vildnex

From your screencast, it seems like you are using a debug build.

In Flutter, everything is way slower in debug mode.

Have you tried testing in release or profile mode?

@Milad-Akarie
Copy link
Owner

@Vildnex try setting the reverse animation duration to zero

@Vildnex
Copy link
Author

Vildnex commented Jul 24, 2024

@Milad-Akarie, I've tested it with the animation duration 0 and also on release mode. In both of those cases, the behavior of the slow animation remains for some reason.

@Vildnex
Copy link
Author

Vildnex commented Aug 25, 2024

@Milad-Akarie any update on this issue? 🤞

@Vildnex
Copy link
Author

Vildnex commented Sep 7, 2024

Hey @Milad-Akarie, I found the solution to this problem:

 @override
  RouteType get defaultRouteType => const RouteType.custom(
        transitionsBuilder: TransitionsBuilders.noTransition,
        durationInMilliseconds: 0,
        reverseDurationInMilliseconds: 0,
      );

I have to add this override in my AppRoute class and use it for all the routes AutoRoute. This is the only way I found so far to fix this issue. But I didn't find it anywhere to be documented.

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

3 participants