Milad-Akarie / auto_route_library

Flutter route generator
MIT License
1.55k stars 392 forks source link

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

Open Vildnex opened 2 months ago

Vildnex commented 2 months ago

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 commented 2 months ago

Update:

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

All of the following are SLOW:

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

Milad-Akarie commented 1 month ago

@vaind try setting the reverse animation duration to zero

Vildnex commented 1 month ago

Hey,

Any update on this bug? @Milad-Akarie

vad-bal commented 1 month ago

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 commented 1 month ago

@Vildnex try setting the reverse animation duration to zero

Vildnex commented 4 weeks ago

@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.