Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

iOS App Freeze for ~0.5 second on Swipe Back Gesture [Flutter] [dart]

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

question from:https://stackoverflow.com/questions/65599653/ios-app-freeze-for-0-5-second-on-swipe-back-gesture-flutter-dart

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...