Skip to content

[Android] Physical keyboard does not work properly  #137405

@savs90

Description

@savs90

Is there an existing issue for this?

Steps to reproduce

Hello Flutter team,

With the last update of Flutter we made for our app we encountered a problem that reflects a big portion of our customers. In Android only (tested in Web and iOS and there everything is fine) physical keyboard or barcode scanner are not usable anymore (no matter if USB or Bluetooth)

Reproducing steps:

  1. Connect some physical keyboard to the Android device
  2. Run the code sample on the Android device (We used Galaxy A52 and Tab A7)
  3. Focus on the text field
  4. Hit some character on the keyboard

Expected results

  1. We expect that the keyboard should behave like in all other applications. This means that even if the virtual keyboard shows on when we first touch an input field, it will be closed and stay closed when we hit some character on the Physical keyboard.
  2. We also expect that after entering a character the input field will not get out of focus

Actual results

In the result of step 4 the text field is getting out of focus the virtual keyboard hides and after that shows up but there is no focus of the field and you have to manually focus the text field again. Using a barcode reader results in entering a maximum the first character of the whole barcode

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter HID Bug',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: FlutterHIDBug(),
    );
  }
}

class FlutterHIDBug extends StatelessWidget {
  final TextEditingController _txtCntrl = TextEditingController();

  FlutterHIDBug({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text("Flutter HID Bug"),
      ),
      body: Center(
        child: TextField(
          controller: _txtCntrl,
          decoration: const InputDecoration(
            border: OutlineInputBorder(),
            hintText: 'Mark and try Physical keyboard entry',
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.8, on macOS 13.5 22G74 darwin-arm64, locale en-DE)
    • Flutter version 3.13.8 on channel stable at /Users/siyan/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6c4930c4ac (9 days ago), 2023-10-18 10:57:55 -0500
    • Engine revision 767d8c75e8
    • Dart version 3.1.4
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/siyan/Library/Android/sdk
    • Platform android-33, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2020.3)
    • 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 11.0.10+0-b96-7249189)

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

[✓] Connected device (4 available)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions