I am using Flutter to develop our mobile app. When I open new screen like this:
Navigator.push(
context,
MaterialPageRoute/CupertinoPageRoute(
builder: (context) => NewScreen(....),
));
and I swipe back using swipe gesture, the UI is not clickable for like 0.5 - 1 seconds afterwards. It makes the app feel unresponsive and slow. What is causing this "freezing"? Is something eating the touch events?
Similar issue: https://github.com/flutter/flutter/issues/48225
I tried investigating this issue using the sample code provided by @edwardez and found out that this is due to...
File: routes.dart Class: _ModalScopeState Function: build(...) Lines:
AnimatedBuilder(
// !!!!!!!!!!!!!!!!!!!!!!!!! userGestureInProgressNotifier becomes true
animation: widget.route.navigator?.userGestureInProgressNotifier ?? ValueNotifier<bool>(false),
builder: (BuildContext context, Widget child) {
final bool ignoreEvents = _shouldIgnoreFocusRequest;
focusScopeNode.canRequestFocus = !ignoreEvents;
return IgnorePointer(
ignoring: false,//ignoreEvents, // <<<<<<<<<<<<<< Tried setting it to FALSE, resolves the issue.
child: child,
);
},
child: child,
),
Setting the IgnorePointer
's ignoring
property to false retains the First screen's animation and resolves the issue.
When I tried setting the userGestureInProgressNotifier
to always return to false, and reverting my changes in IgnorePointer...
File: navigator.dart Function: set _userGesturesInProgress Lines:
set _userGesturesInProgress(int value) {
_userGesturesInProgressCount = value;
//userGestureInProgressNotifier.value = _userGesturesInProgress > 0; // <<<<<< Commented
}
This also resolves the issue but there's no animation for the First screen. (same as pressing back button in AppBar).
My Flutter doctor...
[✓] Flutter (Channel stable, 1.22.5, on macOS 11.1 20C69 darwin-x64, locale en-US)
• Flutter version 1.22.5 at /Users/rickkystiannelim/Documents/sdk/flutter
• Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
• Engine revision ae90085a84
• Dart version 2.10.4
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/rickkystiannelim/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.2, Build version 12B45b
• CocoaPods version 1.9.3
[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.52.1) // <<<<<<<<<<<<<< IDE used
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.18.1
[✓] Connected device (1 available)
• ASUS Z012DA (mobile) • G8AZCY00Z1714K5 • android-arm64 • Android 8.0.0 (API 26) // <<<<<< Device used
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.