Skip to content

TextField issue: TextField doesn't get focus in Android #26563

Closed

Description

@hnvn

I've just upgraded Flutter to v1.1.10-pre.58 and TextField doensn't get focus in Android anymore. (tap in TextField but keyboard doesn't open up)

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.1.10-pre.58, on Microsoft Windows [Version 10.0.17134.523], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.2)
[!] IntelliJ IDEA Community Edition (version 2018.3)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

Activity

  1. taijuan commented on Jan 15, 2019

    @taijuan

    Same as above
    However, it happened in xiaomi phones

  2. lariex commented on Jan 15, 2019

    @lariex

    switching to the dev channel can resolve the problem

  3. hnvn commented on Jan 15, 2019

    @hnvn
    Author

    I have to downgrade to v1.1.9

  4. zoechi commented on Jan 15, 2019

    @zoechi
    Contributor

    To investigate we would need a minimal runnable reproduction
    as a single file so that we can just copy your code into lib/main.dart of a new project and run to reproduce.

  5. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 15, 2019
  6. ncb000gt commented on Jan 16, 2019

    @ncb000gt

    @zoechi Here is something that reproduces the issue for me:

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Flutter Demo'),
          ),
          body: Center(
            child: Column(
              children: <Widget>[
                TextField(
                  decoration: InputDecoration(
                    hintText: 'test',
                    labelText: 'test'
                  )
                ),
              ],
            ),
          ),
        );
      }
    }

    Doctor

    flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel master, v1.1.10-pre.73, on Mac OS X 10.14 18A391, locale en-US)
    [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    [✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    [✓] Android Studio (version 3.1)
    [✓] VS Code (version 1.30.2)
    [✓] Connected device (1 available)
    
    • No issues found!
    

    I'm running Android 9, kernel version 4.4.116-g921edebf2ac5.

    As an aside, I also noticed this when pressing on a text field (sharing in the off chance it is related). I did add some printout to the flutter project and it did seem like some press pressures did go over 1 which is why the assertion triggered. I did a flutter clean and they seemed to go away, but that seemed suspicious to me... Also, when I run this in the iOS emulator it doesn't appear to be an issue and the press pressure is NaN, but I'm guessing that's due to it not being an actual device.

    I/flutter (20454): ══╡ EXCEPTION CAUGHT BY GESTURE LIBRARY ╞═══════════════════════════════════════════════════════════
    I/flutter (20454): The following assertion was thrown while routing a pointer event:
    I/flutter (20454): 'package:flutter/src/gestures/force_press.dart': Failed assertion: line 220 pos 14: 'pressure.isNaN
    I/flutter (20454): ? true : (pressure <= 1.0 && pressure >= 0.0)': is not true.
    I/flutter (20454):
    I/flutter (20454): Either the assertion indicates an error in the framework itself, or we should provide substantially
    I/flutter (20454): more information in this error message to help you determine and fix the underlying cause.
    I/flutter (20454): In either case, please report this assertion by filing a bug on GitHub:
    I/flutter (20454):   https://github.com/flutter/flutter/issues/new?template=BUG.md
    I/flutter (20454):
    I/flutter (20454): When the exception was thrown, this was the stack:
    I/flutter (20454): #2      ForcePressGestureRecognizer.handleEvent (package:flutter/src/gestures/force_press.dart:220:14)
    I/flutter (20454): #3      PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
    I/flutter (20454): #4      PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
    I/flutter (20454): #5      _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
    I/flutter (20454): #6      _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
    I/flutter (20454): #7      _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
    I/flutter (20454): #8      _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
    I/flutter (20454): #9      _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
    I/flutter (20454): #13     _invoke1 (dart:ui/hooks.dart:189:10)
    I/flutter (20454): #14     _dispatchPointerDataPacket (dart:ui/hooks.dart:138:5)
    I/flutter (20454): (elided 5 frames from class _AssertionError and package dart:async)
    I/flutter (20454):
    I/flutter (20454): Event:
    I/flutter (20454):   PointerMoveEvent(Offset(177.1, 106.3))
    I/flutter (20454): ════════════════════════════════════════════════════════════════════════════════════════════════════
    

    And finally, I can confirm, as others have noted, that this is not present on v1.1.9. When I downgraded and reran the application on my phone, the faulty behavior is gone.

  7. fhuonder commented on Jan 16, 2019

    @fhuonder
    Contributor
  8. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jan 16, 2019
  9. zoechi commented on Jan 16, 2019

    @zoechi
    Contributor

    I can reproduce with

    Flutter 1.1.10-pre.76 • channel master • https://github.com/flutter/flutter.git
    Framework • revision 684d050791 (32 minutes ago) • 2019-01-16 01:01:51 -0500
    Engine • revision fdfb0e72f0
    Tools • Dart 2.1.1 (build 2.1.1-dev.1.0 d9944433af)
    
  10. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 16, 2019
  11. zoechi commented on Jan 16, 2019

    @zoechi
    Contributor

    @sdolski #26624 with reference to #26628 might be related

  12. 7 remaining items

  13. Hixie commented on Jan 16, 2019

    @Hixie
    Contributor

    it's the same issue, yes. I hadn't thought through the solution at the time. I think the solution is my comment above.

  14. jslavitz commented on Jan 17, 2019

    @jslavitz
    Contributor

    Ok, this is fixed now everyone! Sorry about that!

  15. goderbauer commented on Jan 17, 2019

    @goderbauer
    Member

    @jslavitz if this is fixed, can we close the issue? Or is there more to do?

  16. xster commented on Jan 17, 2019

    @xster
    Member

    We want to follow through with the other root causes. @jslavitz: feel free to move the list of tasks to another bug though.

  17. xster commented on Feb 25, 2019

    @xster
    Member

    For posterity, this specific issue has been fixed. The last clean-up was #26659

  18. terryl1900 commented on Feb 27, 2019

    @terryl1900

    @xster The issue still happens on iOS simulator when trackpad doesn't support force touch. I suspect it also happens to older iPhone where 3D touch is not supported, but I haven't tried it out.

    Repro:
    Use the app in above thread #26563 (comment)
    iPhone XR simulator, iOS 12.1

    flutter: The following assertion was thrown while dispatching a pointer event:
    flutter: 'package:flutter/src/gestures/force_press.dart': Failed assertion: line 209 pos 12:
    flutter: 'event.pressureMax >= 1.0': is not true.`
    
    flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel dev, v1.2.2, on Mac OS X 10.13.6 17G65, locale en-GB)
    [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    [✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    [✓] Android Studio (version 3.3)
    [✓] Connected device (1 available)
    
    • No issues found!
    
  19. xster commented on Feb 27, 2019

    @xster
    Member

    Sorry for the issue. That was a slightly different issue #28447 and also fixed on master head in #28478

  20. eliezedeck commented on Jun 2, 2019

    @eliezedeck

    While there is no error message whatsoever, for some reason, my TextField still doesn't get focus sometimes.

    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.13.6 17G7024, locale en-MG)
    [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    [✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    [✓] Android Studio (version 3.4)
    [✓] VS Code (version 1.34.0)
    [✓] Connected device (2 available)
    
    • No issues found!
    

    I'm not sure where to start, but sometimes the focus is not happening on Android, sometimes on iOS (iPad). I haven't noticed any correlation yet, and I'll report if I do.

  21. eliezedeck commented on Jun 3, 2019

    @eliezedeck

    Even forcing the CupertinoTextField to have focus like below doesn't do anything. When I keep tapping or long-pressing the text field, it just shows the Paste action, no cursor.

    Here is how I'm forcing the focus:

      FocusNode searchFocus = FocusNode();
    
      @override
      void initState() {
        super.initState();
        Timer(Duration(milliseconds: 500), () {
          FocusScope.of(context).requestFocus(searchFocus);
          debugPrint("forced focus!");
        });
      }

    The forced focus! is printed alright, but no cursor on the text field.

  22. eliezedeck commented on Jun 3, 2019

    @eliezedeck

    Problem solved, after using Flutter v1.6.3 (beta channel).

  23. bianxiang commented on Jan 17, 2020

    @bianxiang

    Problem solved, after using Flutter v1.6.3 (beta channel).

    I use Flutter v1.12.13,how can I fix it?

  24. github-actions commented on Aug 23, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  25. locked as resolved and limited conversation to collaborators on Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: text inputEntering text in a text field or keyboard related problemsc: regressionIt was better in the past than it is nowe: device-specificOnly manifests on certain devicesframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesplatform-androidAndroid applications specifically

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions