Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextField focus bug when transitioning screen #55938

Closed
jezsung opened this issue Apr 29, 2020 · 7 comments
Closed

TextField focus bug when transitioning screen #55938

jezsung opened this issue Apr 29, 2020 · 7 comments
Labels
a: text input Entering text in a text field or keyboard related problems c: regression It was better in the past than it is now f: focus Focus traversal, gaining or losing focus f: material design flutter/packages/flutter/material repository. found in release: 1.12 Found to occur in 1.12 found in release: 1.18 Occurs in 1.18 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on

Comments

@jezsung
Copy link

jezsung commented Apr 29, 2020

ezgif com-video-to-gif

As you can see the above video, after I moved the focus from the first TextField to the second TextField and then when I clicked on '+' button which directs to the second page, the focus moves back to the first TextField and when I go back to the first page, the first TextField gets focus.

I have no clue why this happened and I tried to solve this but no luck at all. It also happened when popping up a dialog.

Below is the code which has no complicated thing at all. Looks like it's a bug.

main.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _controller1 = TextEditingController();
  final _controller2 = TextEditingController();

  @override
  void dispose() {
    _controller1.dispose();
    _controller2.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('hello'),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.add),
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => SecondPage(),
                ),
              );
            },
          )
        ],
      ),
      body: Container(
        padding: const EdgeInsets.all(32),
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              controller: _controller1,
            ),
            TextField(
              controller: _controller2,
            ),
          ],
        ),
      ),
    );
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Second Page'),
      ),
      body: Center(
        child: Text('Second Page'),
      ),
    );
  }
}

pubspec.yaml

name: textfieldtest
description: A new Flutter application.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
@VladyslavBondarenko
Copy link

I can reproduce it with stable v1.12.13+hotfix.9 and dev v1.18.0-8.0.pre, but not with beta v1.17.0-3.3.pre.

flutter doctor -v
[✓] Flutter (Channel dev, v1.18.0-8.0.pre, on Mac OS X 10.15.4 19E287, locale en-GB)
    • Flutter version 1.18.0-8.0.pre at /Users/nevercode/dev/flutter_dev
    • Framework revision e0c63cd35e (5 days ago), 2020-04-23 22:29:01 -0400
    • Engine revision d2ec21221e
    • Dart version 2.9.0 (build 2.9.0-3.0.dev b0d35855d8)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/nevercode/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4.1, Build version 11E503a
    • CocoaPods version 1.9.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.44.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.9.1

 
[✓] Connected device (5 available)            
    • Android SDK built for x86 • emulator-5554                            • android-x86    • Android 10 (API 29) (emulator)
    • Nevercode’s iPhone        • b668e524315069f3db3661ac11ff1f66afafebdb • ios            • iOS 13.4.5
    • macOS                     • macOS                                    • darwin-x64     • Mac OS X 10.15.4 19E287
    • Web Server                • web-server                               • web-javascript • Flutter Tools
    • Chrome                    • chrome                                   • web-javascript • Google Chrome 81.0.4044.129

• No issues found!

@VladyslavBondarenko VladyslavBondarenko added f: focus Focus traversal, gaining or losing focus found in release: 1.12 Found to occur in 1.12 found in release: 1.18 Occurs in 1.18 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on c: regression It was better in the past than it is now labels Apr 29, 2020
@TahaTesser TahaTesser added a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. labels Apr 29, 2020
@HansMuller
Copy link
Contributor

CC @gspencergoog

@gspencergoog gspencergoog removed the f: material design flutter/packages/flutter/material repository. label Apr 29, 2020
@goderbauer
Copy link
Member

@gspencergoog Is this a dup of #48464 or is this different?

@gspencergoog
Copy link
Contributor

gspencergoog commented Apr 29, 2020

It appears to be slightly different in that when returning to the previous route, a control that didn't have focus when the route was pushed is being focused.

I haven't looked into it closely yet, though.

@mzelldev
Copy link

I'm experiencing this issue as well.
I think it's most likely a bug, since Flutter SDK v1.9.1+hotfix.6 doesn't seem to have this problem.

Does anyone know of a possible workaround?

@HansMuller HansMuller added the f: material design flutter/packages/flutter/material repository. label Apr 30, 2020
@pedromassangocode
Copy link

I cannot reproduce this on latest master and stable channel.
Closing a probably fixed.

multiple flutter doctor
/Users/pedromassango/dev/SDKs/flutter_master/bin/flutter doctor --verbose
[✓] Flutter (Channel master, 1.25.0-9.0.pre.86, on Mac OS X 10.15.7 19H2 darwin-x64, locale en)
    • Flutter version 1.25.0-9.0.pre.86 at /Users/pedromassango/dev/SDKs/flutter_master
    • Framework revision 876c313784 (7 hours ago), 2020-12-16 01:23:03 -0500
    • Engine revision a70f6de139
    • Dart version 2.12.0 (build 2.12.0-155.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/pedromassango/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.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Community Edition (version 2020.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 52.0.5
    • Dart plugin version 203.5981.152

[✓] VS Code (version 1.51.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (3 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • macOS (desktop)             • macos         • darwin-x64     • Mac OS X 10.15.7 19H2 darwin-x64
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 87.0.4280.88

• No issues found!
Process finished with exit code 0
/Users/pedromassango/dev/SDKs/flutter_stable/bin/flutter doctor --verbose
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.7 19H2 darwin-x64, locale en)
    • Flutter version 1.22.5 at /Users/pedromassango/dev/SDKs/flutter_stable
    • Framework revision 7891006299 (6 days 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/pedromassango/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.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • 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)

[✓] IntelliJ IDEA Community Edition (version 2020.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin installed
    • Dart plugin version 203.5981.152

[✓] VS Code (version 1.51.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.16.0

[✓] Connected device (1 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

! Doctor found issues in 1 category.
Process finished with exit code 0

@github-actions
Copy link

github-actions bot commented Aug 8, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: text input Entering text in a text field or keyboard related problems c: regression It was better in the past than it is now f: focus Focus traversal, gaining or losing focus f: material design flutter/packages/flutter/material repository. found in release: 1.12 Found to occur in 1.12 found in release: 1.18 Occurs in 1.18 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on
Projects
None yet
Development

No branches or pull requests

8 participants