Skip to content

Material routes have delay on push and pop #88221

Closed

Description

@tomgilder

When using MaterialRoute or MaterialPage on web or desktop, there's a 300ms delay when navigating back from any page. This makes Flutter apps on web and desktop very laggy:

ezgif com-video-to-gif

PR #82596 removed the default animations from web and desktop, but didn't remove the animation transition delay, which is hard coded in MaterialRouteTransitionMixin. The navigator waits for the 300ms transitionDuration before popping the page. This change is in the current beta branch 2.5.0-5.1.pre.

I feel this change should be reverted until there's a solution for the delay: it's better to have an animation rather than a pause that will make developers feel something is broken. It especially feels laggy on web when using the browser's back button.

The hard-coding of the 300ms duration is really problematic; it also means the transition animation is incorrect on iOS (issue #80929). Ideally the transition duration would be provided in the transition themes.

Related issue that users are likely to run into when trying to remove this delay:

Example app code
import 'dart:async';
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(home: PageOne()));
}

class PageOne extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Page one'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            Navigator.of(context).push(
              MaterialPageRoute(builder: (_) => PageTwo()),
            );
          },
          child: const Text('Push page two'),
        ),
      ),
    );
  }
}

class PageTwo extends StatefulWidget {
  @override
  _PageTwoState createState() => _PageTwoState();
}

class _PageTwoState extends State<PageTwo> {
  final _timer = NotifyingTimer();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(
          onPressed: () {
            _timer.go();
            Navigator.pop(context);
          },
        ),
        title: AnimatedBuilder(
          animation: _timer,
          builder: (_, __) => Text('${_timer.stopwatch.elapsedMilliseconds}ms'),
        ),
      ),
    );
  }
}

class NotifyingTimer extends ChangeNotifier {
  final stopwatch = Stopwatch();

  void go() {
    stopwatch.start();
    Timer.periodic(
      const Duration(milliseconds: 1),
      (_) => notifyListeners(),
    );
  }
}

cc @yjbanov @goderbauer @chunhtai @darrenaustin

Activity

  1. TahaTesser commented on Aug 16, 2021

    @TahaTesser
    Contributor

    Hi @tomgilder
    Thanks for filing the issue, I can confirm it is from beta to master, labelling as proposal as the change is intended

    stable beta dev master
    ✅ ❌ ❌ ❌

    Check flutter doctor -v outputs for each channel below

    flutter doctor -v
    [✓] Flutter (Channel stable, 2.2.3, on macOS 12.0 21A5304g darwin-x64, locale en-GB)
        • Flutter version 2.2.3 at /Users/tahatesser/Code/flutter_stable
        • Framework revision f4abaa0735 (7 weeks ago), 2021-07-01 12:46:11 -0700
        • Engine revision 241c87ad80
        • Dart version 2.13.4
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Users/tahatesser/Code/SDK
        • Platform android-31, build-tools 30.0.3
        • ANDROID_HOME = /Users/tahatesser/Code/SDK
        • Java binary at: /Users/tahatesser/Code/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode-beta.app/Contents/Developer
        • Xcode 13.0, Build version 13A5212g
        • CocoaPods version 1.10.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [!] Android Studio (version 2020.3)
        • Android Studio at /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
    
    [✓] VS Code (version 1.59.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.25.0
    
    [✓] Connected device (4 available)
        • Taha’s iPhone (mobile) • 00008020-001059882212002E            • ios            • iOS 15.0
        • iPhone 12 (mobile)     • 7CC8A747-CD39-4C42-871C-2D1CCEAE2AE2 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
        • macOS (desktop)        • macos                                • darwin-x64     • macOS 12.0 21A5304g darwin-x64
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 92.0.4515.131
    
    ! Doctor found issues in 1 category.
    [✓] Flutter (Channel beta, 2.5.0-5.1.pre, on macOS 12.0 21A5304g darwin-x64, locale en-GB)
        • Flutter version 2.5.0-5.1.pre at /Users/tahatesser/Code/flutter_beta
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 65cf7de5f4 (5 days ago), 2021-08-11 15:48:01 -0700
        • Engine revision fbeb7e22bd
        • Dart version 2.14.0 (build 2.14.0-377.4.beta)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Users/tahatesser/Code/SDK
        • Platform android-31, build-tools 30.0.3
        • ANDROID_HOME = /Users/tahatesser/Code/SDK
        • Java binary at: /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode-beta.app/Contents/Developer
        • Xcode 13.0, Build version 13A5212g
        • CocoaPods version 1.10.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    
    [✓] VS Code (version 1.59.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.25.0
    
    [✓] Connected device (4 available)
        • Taha’s iPhone (mobile) • 00008020-001059882212002E            • ios            • iOS 15.0 19A5318f
        • iPhone 12 (mobile)     • 7CC8A747-CD39-4C42-871C-2D1CCEAE2AE2 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
        • macOS (desktop)        • macos                                • darwin-x64     • macOS 12.0 21A5304g darwin-x64
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 92.0.4515.131
    
    • No issues found!
    [✓] Flutter (Channel dev, 2.5.0-6.0.pre, on macOS 12.0 21A5304g darwin-x64, locale en-GB)
        • Flutter version 2.5.0-6.0.pre at /Users/tahatesser/Code/flutter_dev
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 225a43d941 (11 days ago), 2021-08-05 11:32:48 -0700
        • Engine revision 07ec4b82c7
        • Dart version 2.14.0 (build 2.14.0-383.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Users/tahatesser/Code/SDK
        • Platform android-31, build-tools 30.0.3
        • ANDROID_HOME = /Users/tahatesser/Code/SDK
        • Java binary at: /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode-beta.app/Contents/Developer
        • Xcode 13.0, Build version 13A5212g
        • CocoaPods version 1.10.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    
    [✓] VS Code (version 1.59.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.25.0
    
    [✓] Connected device (4 available)
        • Taha’s iPhone (mobile) • 00008020-001059882212002E            • ios            • iOS 15.0 19A5318f
        • iPhone 12 (mobile)     • 7CC8A747-CD39-4C42-871C-2D1CCEAE2AE2 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
        • macOS (desktop)        • macos                                • darwin-x64     • macOS 12.0 21A5304g darwin-x64
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 92.0.4515.131
    
    • No issues found!
    [✓] Flutter (Channel master, 2.5.0-7.0.pre.83, on macOS 12.0 21A5304g darwin-x64, locale en-GB)
        • Flutter version 2.5.0-7.0.pre.83 at /Users/tahatesser/Code/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 06be7e5392 (19 hours ago), 2021-08-15 14:37:02 -0400
        • Engine revision 1af0a20793
        • Dart version 2.15.0 (build 2.15.0-15.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Users/tahatesser/Code/SDK
        • Platform android-31, build-tools 30.0.3
        • ANDROID_HOME = /Users/tahatesser/Code/SDK
        • Java binary at: /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode-beta.app/Contents/Developer
        • Xcode 13.0, Build version 13A5212g
        • CocoaPods version 1.10.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Users/tahatesser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    
    [✓] VS Code (version 1.59.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.25.0
    
    [✓] Connected device (4 available)
        • Taha’s iPhone (mobile) • 00008020-001059882212002E            • ios            • iOS 15.0 19A5318f
        • iPhone 12 (mobile)     • 7CC8A747-CD39-4C42-871C-2D1CCEAE2AE2 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
        • macOS (desktop)        • macos                                • darwin-x64     • macOS 12.0 21A5304g darwin-x64
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 92.0.4515.131
    
    • No issues found!
    

    ✅: No Issue ❌: Issue reproduced

  2. added
    p: material_uimaterial_ui package in flutter/packages
    f: routesNavigator, Router, and related APIs.
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Aug 16, 2021
  3. tomgilder commented on Aug 16, 2021

    @tomgilder
    ContributorAuthor

    I'd say this is pretty clearly a bug - I don't believe keeping the delay was intentional

  4. Goncharo commented on Sep 9, 2021

    @Goncharo

    +1 one for this, however it is worth noting that I'm seeing this on MaterialPage pushes as well (using Nav 2.0), and definitely looks like a bug.

    Upgraded to 2.5.0 this morning, and spent some time diagnosing why the MaterialPage transitions were now seemingly different between mobile and desktop/web. As mentioned above, it seems like PR #82596 removed the default transitions, however the animation delay is still there for both pops and pushes.

    Agreed with @tomgilder that this PR should probably be reverted, otherwise need to have some fix in place. As of now, the default MaterialPage behavior looks fairly broken on web/desktop.

  5. rydmike commented on Sep 10, 2021

    @rydmike
    Contributor

    Yes indeed @Goncharo the issue has sadly now regressed into release 2.5.0 stable release. since it was never addressed in the 2.5 pre-release versions earlier.

  6. changed the title [-]Material routes have delay on pop[/-] [+]Material routes have delay on push and pop[/+] on Sep 10, 2021
  7. rydmike commented on Sep 10, 2021

    @rydmike
    Contributor

    @TahaTesser since this issue has now regressed into stable 2.5.0 the affected channels should be updated, and it now needs some attention and high prio too.

    Imo this issue now needs a 2.5.1 hotfix release where it is reverted if the actual fix to implement it correctly takes too long implement and deliver. Better to have an animation that starts at once, than to wait the animation time before anything happens - I'm with @tomgilder on that.

  8. 5 remaining items

  9. darrenaustin commented on Sep 13, 2021

    @darrenaustin
    Contributor

    Apologies for not catching this before it went into stable. I am investigating removing the delay when there is no transition. If I can't do that quickly and safely, I will revert it.

    However, if you need a work around for right now, you can put back the original behaviour by adding the previous default transitions to your app's theme:

    MaterialApp(
      theme: ThemeData(
          pageTransitionsTheme: const PageTransitionsTheme(
            builders: <TargetPlatform, PageTransitionsBuilder>{
              TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
              TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
              TargetPlatform.linux: FadeUpwardsPageTransitionsBuilder(),
              TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
              TargetPlatform.windows: FadeUpwardsPageTransitionsBuilder(),
            },
          )
      )
    )
  10. tomgilder commented on Sep 13, 2021

    @tomgilder
    ContributorAuthor

    @darrenaustin thank you!

    If you'd like a suggestion as to how to fix this longer term, I came up with a TransitionPage for my package that I think works quite well for users.

    It defines a PageTransition object with duration and transitionsBuilder properties, I think something similar in Flutter would work well.

  11. chunhtai commented on Sep 13, 2021

    @chunhtai
    Contributor

    One idea is add transition duration to the PageTransitionsTheme, and grab that duration in

    Duration get transitionDuration => const Duration(milliseconds: 300);

    One problem with the approach is that it doesn't have context at that point, but the Route has access to navigator state, we can probably grab the context from it

  12. HansMuller commented on Sep 13, 2021

    @HansMuller
    Contributor

    Reverting #82596 until we can resolve this issue to everyone's satisfaction is the right thing to do in the short-term. The "cp: 2.5" label LGTM.

  13. maheshj01 commented on Sep 24, 2021

    @maheshj01
    Member

    Adding the Desktop and web labels, since this issue is only on those platforms.

  14. darrenaustin commented on Feb 24, 2022

    @darrenaustin
    Contributor

    As the change that caused this delay has been reverted, I am going to close this issue. I will open another one to track changing the default transition for desktop and web to be a zero delay transition.

  15. github-actions commented on Mar 10, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  16. locked as resolved and limited conversation to collaborators on Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: desktopRunning on desktopc: regressionIt was better in the past than it is nowcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.f: routesNavigator, Router, and related APIs.found in release: 2.5Found to occur in 2.5frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesplatform-webWeb applications specifically

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions