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

735

Solution 1

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.

Solution 2

Try printing with an integer variable that gets incremented every time you press the icon. Prints the way you want.

GestureDetector(
            child: Icon(Icons.person,color: Colors.black54,),
            
            onTap: (){
              i = i+1;
              print("clicked person:$i");},
            behavior: HitTestBehavior.translucent
          ),
Share:
735
Nurol Alacaatli
Author by

Nurol Alacaatli

Updated on December 27, 2022

Comments

  • Nurol Alacaatli
    Nurol Alacaatli over 1 year

    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.

    • dm_tr
      dm_tr over 3 years
      This happens due to the slowness of your system
    • Nurol Alacaatli
      Nurol Alacaatli over 3 years
      I thought this but the default sample code (the code which comes when a new flutter application created) works properly without any delay.
  • dm_tr
    dm_tr over 3 years
    You said print statement might sometimes get delayed ??
  • Nurol Alacaatli
    Nurol Alacaatli over 3 years
    Delay problem has been solved. Print statement occurs delay. Thank you very much.
  • Nurol Alacaatli
    Nurol Alacaatli over 3 years
    I tried to install dart and flutter plugins for several times, also I uninstall everything and install again (including git, flutter, dart, android studio ...) but couldn't solve this problem. My application is working properly by the way but flutter doctor does not see those plugins are installed.
  • Nurol Alacaatli
    Nurol Alacaatli about 3 years
    GestureDetector works fine on emulator/phone, only print statements delayed in particular scenario. For example if you want to write an integer 10 times and lets say that integer never changes... In that scenario in the terminal screen you see the first value of that integer variable, and then (a little wait, maybe 3 seconds) you see "8xidentical lines" message and last value of integer variable. I think result screen somehow summarize the values which will be shown soon. Gesture Detector works fine if your change state on the screen, you can see realtime results. Thank you for contribution.