Skip to content

[Add2App] The typed characters in a TextField are lost when backgrounding the app with focus on the TextField on Android #47137

Description

@dannyvalentesonos

Using the new embedding API for Android to embed Flutter in an existing app, it is possible for the TextField to lose its last typed characters when backgrounding the app on Android.

The following simple Flutter module code will create a TextField.

Launch the Flutter module in the existing app
Start typing text in the field
With focus still in the field, background the app using the Home button
Come back to the app. Notice the focus is still in the field and the keyboard is hidden, but the characters disappear.

If you take focus off of the TextField before backgrounding the app, then when coming back, the characters remain.

This is related to #35054, but the fix for that bug either introduced this or revealed it.

The following is the code in the flutter module:

// Main app entry
void main() {
   runApp(MyApp());
}

class DefaultEmptyPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
            child: TextField(
              decoration: InputDecoration(
                  labelText: "Enter Text"
              ),
            )
        )
    );
  }
}

class MyApp extends StatelessWidget {
  MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'My App',
      home: DefaultEmptyPage(),
    );
  }
}

Activity

  1. dannyvalentesonos commented on Dec 16, 2019

    @dannyvalentesonos
    ContributorAuthor

    @dnfield #35054 is fixed, but now this bug is happening.
    Thanks

  2. dnfield commented on Dec 16, 2019

    @dnfield
    Contributor
  3. added
    a: existing-appsIntegration with existing apps via the add-to-app flow
    a: text inputEntering text in a text field or keyboard related problems
    platform-androidAndroid applications specifically
    on Dec 16, 2019
  4. added
    engineflutter/engine related. See also e: labels.
    frameworkflutter/packages/flutter repository. See also f: labels.
    and removed on Dec 16, 2019
  5. dnfield commented on Dec 16, 2019

    @dnfield
    Contributor

    @iapicca this is very unlikely to require input from the Android team :) removing the dependency label.

    This probably needs changes in engine or framework, possibly both. Adding those.

  6. matthew-carroll commented on Dec 16, 2019

    @matthew-carroll
    Contributor

    @dnfield any idea if there is some kind of flushing logic that takes place when removing focus from a textfield that therefore wouldn't be triggered upon app backgrounding?

  7. dnfield commented on Dec 16, 2019

    @dnfield
    Contributor

    This is reproducible for any app with the new embedding - it's not add2app specific.

  8. added
    customer: crowdAffects or could affect many people, though not necessarily a specific customer.
    on Dec 16, 2019
  9. self-assigned this
    on Dec 16, 2019
  10. added this to the December 2019 milestone on Dec 16, 2019
  11. removed
    engineflutter/engine related. See also e: labels.
    on Dec 16, 2019
  12. dnfield commented on Dec 16, 2019

    @dnfield
    Contributor

    I have a fix for this. Writing a test now.

  13. dnfield commented on Dec 16, 2019

    @dnfield
    Contributor

    @matthew-carroll - it's something like that, yes.

  14. voiddog commented on Dec 17, 2019

    @voiddog

    Same problem too

  15. dnfield commented on Dec 19, 2019

    @dnfield
    Contributor

    The fix for this introduced some other unexpected breakages. It's going to be reverted until I can work that out.

  16. dnfield commented on Dec 19, 2019

    @dnfield
    Contributor

    I believe I have another, safer fix for this.

  17. github-actions commented on Aug 24, 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.

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

Metadata

Metadata

Assignees

Labels

a: existing-appsIntegration with existing apps via the add-to-app flowa: text inputEntering text in a text field or keyboard related problemscustomer: crowdAffects or could affect many people, though not necessarily a specific customer.frameworkflutter/packages/flutter repository. See also f: labels.platform-androidAndroid applications specificallywaiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions