flutter icon indicating copy to clipboard operation
flutter copied to clipboard

RawKeyboardListener & Focus onKey callback doesn't working on IOS (reproduce on Iphone 6 & Iphone13 pro)

Open SungHyun22 opened this issue 2 years ago • 7 comments

onKey Callback from RawKeyboardListener and Focus Widget not working on iphone6 & Iphone 13 pro. But in the simulator it works fine. Only Iphone6 & Iphone13 pro ​​reproduces this problem.

Steps to Reproduce

try run this code on Iphone6 & Iphone13 pro

import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'RawKeyboardListener onKey error',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late FocusNode _focusNode;

  @override
  void initState() {
    super.initState();
    _focusNode = FocusNode();
  }

  @override
  void dispose() {
    _focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("RawKeybaordListener onKey error"),
      ),
      body: RawKeyboardListener(
        focusNode: _focusNode,
        onKey: (event) {
          // doesn't working
          print(event);
        },
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: const <Widget>[
              TextField(),
            ],
          ),
        ),
      ),
    );
  }
}

flutter doctor

[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-arm, locale ko-KR) • Flutter version 3.0.5 • Upstream repository https://github.com/flutter/flutter.git • Framework revision f1875d570e (9 days ago), 2022-07-13 11:24:16 -0700 • Engine revision e85ea0e79c • Dart version 2.17.6 • DevTools version 2.12.2 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK • Platform android-31, build-tools 30.0.3 • 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 13.4.1) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.11.3 [✓] 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: :hammer: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: :hammer: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) [✓] VS Code (version 1.69.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.44.0

SungHyun22 avatar Jul 23 '22 02:07 SungHyun22

Thanks for the report @SungHyun22 What's the expected result are you looking for after running code sample ?

darshankawar avatar Jul 25 '22 05:07 darshankawar

Our team pressed the enter key and the backspace key on the keyboard. But onKey callback does not print any events. Our team reproduced this problem from iPhone 6 and iPhone 13 Pro. In addition, iPhone simulators, Galaxy Note 5, and Galaxy S9 confirmed that onKey callback was working properly

SungHyun22 avatar Jul 25 '22 06:07 SungHyun22

Thanks for the update @SungHyun22. According to this merged PR : https://github.com/flutter/flutter/pull/101537, can you try using Focus widget instead of RawKeyboardListener and see if you get desired behavior on same devices ?

darshankawar avatar Jul 26 '22 05:07 darshankawar

Thank you for response @darshankawar. We already test using focus. But the result is same. onKey callback doesn't work. 😥😥

SungHyun22 avatar Jul 27 '22 00:07 SungHyun22

Thanks for the update. Running code sample on iPhone 6s with latest stable and master doesn't show onKey press events:

Syncing files to device Darshan's iphone...
fopen failed for data file: errno = 2 (No such file or directory)
Errors found! Invalidating cache...
fopen failed for data file: errno = 2 (No such file or directory)
Errors found! Invalidating cache...

But the same is shown on iOS simulator:

Debug service listening on ws://127.0.0.1:49854/ujh5hvC6nJU=/ws
Syncing files to device iPhone 13...
flutter: RawKeyDownEvent#a5091(logicalKey: LogicalKeyboardKey#00106(keyId: "0x200000106", keyLabel: "Meta Left", debugName: "Meta Left"), physicalKey: PhysicalKeyboardKey#700e3(usbHidUsage: "0x000700e3", debugName: "Meta Left"), repeat: false)
flutter: RawKeyDownEvent#36cbb(logicalKey: LogicalKeyboardKey#000b8(keyId: "0x13000000b8", keyLabel: "", debugName: "Key with ID 0x013000000b8"), physicalKey: PhysicalKeyboardKey#000b8(usbHidUsage: "0x13000000b8", debugName: "Key with ID 0x13000000b8"), repeat: false)
flutter: RawKeyUpEvent#1c6b9(logicalKey: LogicalKeyboardKey#000b8(keyId: "0x13000000b8", keyLabel: "", debugName: "Key with ID 0x013000000b8"), physicalKey: PhysicalKeyboardKey#000b8(usbHidUsage: "0x13000000b8", debugName: "Key with ID 0x13000000b8"))
flutter: RawKeyUpEvent#790b2(logicalKey: LogicalKeyboardKey#00106(keyId: "0x200000106", keyLabel: "Meta Left", debugName: "Meta Left"), physicalKey: PhysicalKeyboardKey#700e3(usbHidUsage: "0x000700e3", debugName: "Meta Left"))
stable, master flutter doctor -v

[✓] Flutter (Channel stable, 3.0.5, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.0.5 at /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (2 days ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

[✓] Flutter (Channel master, 3.1.0-0.0.pre.1894, on macOS 12.2.1 21D62
    darwin-x64, locale en-GB)
    • Flutter version 3.1.0-0.0.pre.1894 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f48478a21b (88 minutes ago), 2022-07-26 23:38:06 -0400
    • Engine revision 609f1abf0f
    • Dart version 2.19.0 (build 2.19.0-36.0.dev)
    • DevTools version 2.15.0
    
[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.



darshankawar avatar Jul 27 '22 06:07 darshankawar

CC @dkwingsmt

antholeole avatar Jul 28 '22 22:07 antholeole

anything update here?

SungHyun22 avatar Dec 13 '22 07:12 SungHyun22

I'm having this problem, too.

Is there still no way to solve it?

@antholeole @chinmaygarde @dkwingsmt

JunHyunJunHyun avatar Feb 18 '23 08:02 JunHyunJunHyun

any update on this ?

himsarevenus avatar May 08 '23 06:05 himsarevenus

Any progress? Currently, I have only tested on iPhone 8 and iPhone 14. The Focus.onKey method responds to operations on the physical keyboard, but not to operations on the on-screen keyboard.

Dboy233 avatar Jun 06 '23 08:06 Dboy233

I'm having the same problem. Any updates on the issue?

koraybilgi avatar Aug 30 '23 21:08 koraybilgi

mark

M2dL1fe avatar Nov 02 '23 07:11 M2dL1fe

same issue here, any update?

Shailendra-3Frames avatar Nov 08 '23 16:11 Shailendra-3Frames

I am also facing same issue , any update ?

vishnu3frames avatar Nov 08 '23 16:11 vishnu3frames

Please upvote original issue description instead of asking for updates. The issue has high chances of getting attention based on number of upvotes.

darshankawar avatar Nov 09 '23 05:11 darshankawar

The new KeyboardListener still has this problem

M2dL1fe avatar Jan 12 '24 05:01 M2dL1fe

Any workaround or fix for this?

AkhileshManda avatar Aug 01 '24 06:08 AkhileshManda

Waiting for a response

JXWeiJun avatar Aug 02 '24 04:08 JXWeiJun