android-studiofluttergesturedetector

GestureDetector OnTap Delay on Android Studio / Flutter / Nexus 6 API 30


Think about extremly simple flutter application that contains one Container widget on the screen and GestureDetector on it.

main goes to myApp, main and myApp widgets are in the same dart file. myApp goes to HomePage which is a different dart file. HomePage has one Container and GestureDetector widgets.

GestureDetector's onTap function is : print('pressed');

"pressed" appears for the first time when container tapped. The problem is when I tapped for several times on this container. "pressed" appears after a delay. Sometimes I see it after compilers' message.

uid=10153(com.example.vocabulary_master_8) 1.ui identical 4 lines

Here is my flutter doctor -v finding.

[!] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

After I upgrade Android Studio to 4.1.2 and Nexus 6 API 30, I started to get this error and delay.

Could you please somebody help? Best regards.


Solution

  • Firstly you should install the Dart plugin as dectected by flutter doctor.

    Coming to your issue, there can be many reasons for the delay :

    1. I guess you are running it in debug mode on an emulator, the performance in debug mode will be slow and laggy compared to release mode. To test the app in release mode, use a real device instead of an emulator and instead of flutter run, use flutter run --release.

    2. print statement might sometimes get delayed. Instead of trying to print something try updating your UI on tap. And as seen in the above scenario, as you are tapping several times, you are forcing the debugger to print the same statement multiple times, hence in case of flutter, it check if the print statements are same or not, if they are same, it will combine all of them and print an output like this :

    uid=10153(com.example.vocabulary_master_8) 1.ui identical 4 lines
    

    after a certian delay.

    So in short you code is working fine, the delay is caused because flutter takes some time to recognize and combine the similar print statements.