CharacterActivator is not triggered in a Flutter app when using a hardware keyboard connected to an iOS device or simulator. It works on Android.
When testing on physical devices I used an MX Keys keyboard connected via Bluetooth. For the iOS simulator test, I used the built-in keyboard on the host machine.
Execute flutter run on the code sample
Observe the text "Ask a question"
Hold down Shift and press the "/" key to produce the character "?"
Expected results:
Screen shows "Good question!" because CharacterActivator triggered.
Actual results:
On Android, it works. On iOS, the screen continues to show "Ask a question"
You can edit the code sample to try to detect other characters and it still doesn't work on iOS.
Code sample
```dart
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State createState() => _MyAppState();
}
class _MyAppState extends State {
String _text = "Ask a question";
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Center(
child: CallbackShortcuts(
bindings: {
const CharacterActivator('?'): () {
setState(() {
_text = "Good question!";
});
},
},
child: Focus(
autofocus: true,
child: Text(_text, style: const TextStyle(fontSize: 40)),
),
),
),
),
);
}
}
```
Logs
```
[ +57 ms] Successfully connected to service protocol: http://127.0.0.1:53908/
[ +26 ms] DevFS: Creating new filesystem on the device (null)
[ +22 ms] DevFS: Created new filesystem on the device
(file:///private/var/mobile/Containers/Data/Application/BE9A4251-21C9-4C17-91C4-E11CE48A7DDF/tmp/hardware_keyboard_testjZQdq7/hardware_keyboard_test/)
[ +2 ms] Updating assets
[ +66 ms] Syncing files to device iPhone...
[ +1 ms] <- reset
[ ] Compiling dart to kernel with 0 updated files
[ ] Processing bundle.
[ +1 ms] <- recompile package:hardware_keyboard_test/main.dart 1938f5a0-62cb-4a62-9da0-6d8bb6d4313a
[ ] <- 1938f5a0-62cb-4a62-9da0-6d8bb6d4313a
[ +1 ms] Bundle processing done.
[ +54 ms] Updating files.
[ ] DevFS: Sync finished
[ +1 ms] Syncing files to device iPhone... (completed in 59ms)
[ ] Synced 0.0MB.
[ +2 ms] <- accept
[ +18 ms] Connected to _flutterView/0x139820e20.
[ +2 ms] Flutter run key commands.
[ +1 ms] r Hot reload. 🔥🔥🔥
[ ] R Hot restart.
[ ] h List all available interactive commands.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] 💪 Running with sound null safety 💪
[ ] An Observatory debugger and profiler on iPhone is available at: http://127.0.0.1:53913/mpJJYIx8pS4=/
[ +46 ms] The Flutter DevTools debugger and profiler on iPhone is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:53913/mpJJYIx8pS4=/
```
```
Analyzing hardware_keyboard_test...
No issues found! (ran in 1.8s)
```
Flutter doctor shows an issue with IntelliJ but I don't think it's related. I'm launching using the command line.
```
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.2 21D49 darwin-x64, locale en-US)
• Flutter version 2.10.2 at /Users/jackson/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 097d3313d8 (9 days ago), 2022-02-18 19:33:08 -0600
• Engine revision a83ed0e5e3
• Dart version 2.16.1
• DevTools version 2.9.2
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/jackson/Library/Android/sdk
• Platform android-32, build-tools 32.0.0
• ANDROID_SDK_ROOT = /home/jackson/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• 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-7281165)
[☠] IntelliJ IDEA Community Edition (the doctor check crashed)
✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at
https://github.com/flutter/flutter/issues.
✗ FormatException: Unexpected extension byte (at offset 5)
• #0 _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1789:7)
#1 Utf8Decoder.convert (dart:convert/utf.dart:351:42)
#2 InputStream.readString (package:archive/src/util/input_stream.dart:207:30)
#3 new ZipDirectory.read (package:archive/src/zip/zip_directory.dart:40:30)
#4 ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:19:30)
#5 ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:14:12)
#6 IntelliJPlugins._findPluginXml (package:flutter_tools/src/intellij/intellij.dart:130:44)
#7 IntelliJPlugins._readPackageVersion (package:flutter_tools/src/intellij/intellij.dart:141:40)
#8 IntelliJPlugins.validatePackage (package:flutter_tools/src/intellij/intellij.dart:63:35)
#9 IntelliJValidator.validate (package:flutter_tools/src/intellij/intellij_validator.dart:103:15)
#10 asyncGuard. (package:flutter_tools/src/base/async_guard.dart:111:32)
#11 asyncGuard. (package:flutter_tools/src/base/async_guard.dart:109:18)
#12 _rootRun (dart:async/zone.dart:1426:13)
#13 _CustomZone.run (dart:async/zone.dart:1328:19)
#14 _runZoned (dart:async/zone.dart:1861:10)
#15 runZonedGuarded (dart:async/zone.dart:1849:12)
#16 runZoned (dart:async/zone.dart:1780:12)
#17 asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
#18 Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:205:9)
#19 Doctor.diagnose (package:flutter_tools/src/doctor.dart:309:47)
#20 DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:50:48)
#21 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1320:12)
#22 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1161:27)
#23 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19)
#24 CommandRunner.runCommand (package:args/command_runner.dart:209:13)
#25 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
#26 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19)
#27 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
#28 run.. (package:flutter_tools/runner.dart:62:9)
#29 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19)
#30 main (package:flutter_tools/executable.dart:94:3)
[✓] Connected device (5 available)
• SM A125U (mobile) • R58R85BBCAV • android-arm64 • Android 11 (API 30)
• iPhone (mobile) • 00008101-001155042188801E • ios • iOS 15.1 19B74
• iPhone 12 Pro (mobile) • 132369FE-696E-42C9-B0F4-EE1A24E377FC • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.2 21D49 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.109
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
```
Steps to Reproduce
CharacterActivator
is not triggered in a Flutter app when using a hardware keyboard connected to an iOS device or simulator. It works on Android.When testing on physical devices I used an MX Keys keyboard connected via Bluetooth. For the iOS simulator test, I used the built-in keyboard on the host machine.
flutter run
on the code sampleExpected results: Screen shows "Good question!" because
CharacterActivator
triggered.Actual results: On Android, it works. On iOS, the screen continues to show "Ask a question"
You can edit the code sample to try to detect other characters and it still doesn't work on iOS.
Code sample
```dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @override StateLogs
``` [ +57 ms] Successfully connected to service protocol: http://127.0.0.1:53908/ [ +26 ms] DevFS: Creating new filesystem on the device (null) [ +22 ms] DevFS: Created new filesystem on the device (file:///private/var/mobile/Containers/Data/Application/BE9A4251-21C9-4C17-91C4-E11CE48A7DDF/tmp/hardware_keyboard_testjZQdq7/hardware_keyboard_test/) [ +2 ms] Updating assets [ +66 ms] Syncing files to device iPhone... [ +1 ms] <- reset [ ] Compiling dart to kernel with 0 updated files [ ] Processing bundle. [ +1 ms] <- recompile package:hardware_keyboard_test/main.dart 1938f5a0-62cb-4a62-9da0-6d8bb6d4313a [ ] <- 1938f5a0-62cb-4a62-9da0-6d8bb6d4313a [ +1 ms] Bundle processing done. [ +54 ms] Updating files. [ ] DevFS: Sync finished [ +1 ms] Syncing files to device iPhone... (completed in 59ms) [ ] Synced 0.0MB. [ +2 ms] <- accept [ +18 ms] Connected to _flutterView/0x139820e20. [ +2 ms] Flutter run key commands. [ +1 ms] r Hot reload. 🔥🔥🔥 [ ] R Hot restart. [ ] h List all available interactive commands. [ ] d Detach (terminate "flutter run" but leave application running). [ ] c Clear the screen [ ] q Quit (terminate the application on the device). [ ] 💪 Running with sound null safety 💪 [ ] An Observatory debugger and profiler on iPhone is available at: http://127.0.0.1:53913/mpJJYIx8pS4=/ [ +46 ms] The Flutter DevTools debugger and profiler on iPhone is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:53913/mpJJYIx8pS4=/ ``` ``` Analyzing hardware_keyboard_test... No issues found! (ran in 1.8s) ``` Flutter doctor shows an issue with IntelliJ but I don't think it's related. I'm launching using the command line. ``` [✓] Flutter (Channel stable, 2.10.2, on macOS 12.2 21D49 darwin-x64, locale en-US) • Flutter version 2.10.2 at /Users/jackson/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 097d3313d8 (9 days ago), 2022-02-18 19:33:08 -0600 • Engine revision a83ed0e5e3 • Dart version 2.16.1 • DevTools version 2.9.2 [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) • Android SDK at /Users/jackson/Library/Android/sdk • Platform android-32, build-tools 32.0.0 • ANDROID_SDK_ROOT = /home/jackson/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • 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-7281165) [☠] IntelliJ IDEA Community Edition (the doctor check crashed) ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues. ✗ FormatException: Unexpected extension byte (at offset 5) • #0 _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1789:7) #1 Utf8Decoder.convert (dart:convert/utf.dart:351:42) #2 InputStream.readString (package:archive/src/util/input_stream.dart:207:30) #3 new ZipDirectory.read (package:archive/src/zip/zip_directory.dart:40:30) #4 ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:19:30) #5 ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:14:12) #6 IntelliJPlugins._findPluginXml (package:flutter_tools/src/intellij/intellij.dart:130:44) #7 IntelliJPlugins._readPackageVersion (package:flutter_tools/src/intellij/intellij.dart:141:40) #8 IntelliJPlugins.validatePackage (package:flutter_tools/src/intellij/intellij.dart:63:35) #9 IntelliJValidator.validate (package:flutter_tools/src/intellij/intellij_validator.dart:103:15) #10 asyncGuard.Possibly related issue: https://github.com/flutter/flutter/issues/99252