In Navigator 2.0, two transitions occur when the buttons are tapped at the same time; in Navigator 1.0, this does not occur.
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
# Overview
As the title suggests, in Navigator 2.0, two transitions occur when the buttons are tapped at the same time. On the other hand, Navigator 1.0 does not.
I am not sure which is the expected behavior, but there is a processing difference, so I have raised this as an issue.
| Behavior of Navigator1.0 when simultaneously tapped | Behavior of Navigator2.0 when simultaneously tapped |
----|----
|  |  |
Smaple code
```dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => AppState(),
child: MaterialApp.router(
title: 'Navigator 2.0 Sample',
routerDelegate: SampleRouterDelegate(),
),
);
}
}
class AppState with ChangeNotifier {
final List _pages = [HomePage.page()];
List get pages => List.unmodifiable(_pages);
void pushPage({required MaterialPage page}) {
_pages.add(page);
notifyListeners();
}
void popPage() {
_pages.removeLast();
notifyListeners();
}
}
class SampleRouterDelegate extends RouterDelegate with ChangeNotifier {
SampleRouterDelegate();
final navigatorKey = GlobalKey();
@override
Widget build(BuildContext context) {
final pages = context.select((AppState state) => state.pages);
return Navigator(
key: navigatorKey,
pages: pages,
onPopPage: (route, result) {
if (!route.didPop(result)) {
return false;
}
context.read().popPage();
return true;
},
);
}
@override
Future popRoute() {
return navigatorKey.currentState!.maybePop();
}
@override
Future setNewRoutePath(Object configuration) => Future.value();
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
static MaterialPage page() => const MaterialPage(child: HomePage());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Home Page'),
),
body: Center(
child: Column(
children: [
TextButton(
onPressed: () {
context.read().pushPage(page: NextPage.page());
// Navigator.of(context).push(MaterialPageRoute(builder: (_) => const NextPage())); // Navigator 1.0 API does not reproduce double transition.
},
child: const Text('Try double tap'),
),
TextButton(
onPressed: () {
context.read().pushPage(page: NextPage.page());
// Navigator.of(context).push(MaterialPageRoute(builder: (_) => const NextPage()));// Navigator 1.0 API does not reproduce double transition
},
child: const Text('Try double tap'),
),
],
),
),
);
}
}
class NextPage extends StatelessWidget {
const NextPage({super.key});
static MaterialPage page() => const MaterialPage(child: NextPage());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Next Page'),
),
body: const Center(
child: Text('This is the next page'),
),
);
}
}
```
pubspec.yaml
```yaml
name: try_double_tap
description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: '>=2.19.2 <3.0.0'
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
provider: ^6.0.2
flutter:
uses-material-design: true
```
flutter doctor -v
```
➜ try_double_tap git:(main) ✗ flutter doctor -v
[✓] Flutter (Channel stable, 3.16.0, on macOS 13.4 22F66 darwin-arm64, locale ja-JP)
• Flutter version 3.16.0 on channel stable at /Users/01036096/fvm/versions/3.16.0
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision db7ef5bf9f (3 weeks ago), 2023-11-15 11:25:44 -0800
• Engine revision 74d16627b9
• Dart version 3.2.0
• DevTools version 2.28.2
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
• Android SDK at /Users/01036096/Library/Android/sdk
• Platform android-33, build-tools 33.0.2
• ANDROID_HOME = /Users/01036096/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode14.1.app/Contents/Developer
• Build 14B47b
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/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 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.84.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.78.0
[✓] Connected device (5 available)
• iPhone SE (3rd generation) (mobile) • 7513382E-635C-412E-95AC-5938A0ECFB1D • ios •
com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
• iPhone 14 Pro (mobile) • 9BB12B43-7CEC-44FB-9F08-74F4B0512AC8 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
• iPhone 13 (mobile) • D6FC6A2C-CB76-4483-B26B-DB82EC74DCE5 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.4 22F66 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.199
[✓] Network resources
• All expected network resources are available.
• No issues found!
```
Contributor guide
Assessment
This issue has not been assessed yet.