我使用外部条形码设备进行输入(带有扫描+提交(输入)组合)。 我将RawKeyboardListener作为TextField父级,但是在扫描时不起作用。它看到回车键但没有条形码并给出一些错误;
对Android的平台键支持产生了不受支持的修饰符 组合。 'package:flutter / src / services / raw_keyboard.dart':失败 断言:721行pos 11:“空”
raw_keyboard.dart
final Map<ModifierKey, KeyboardSide> modifiersPressed =
event.data.modifiersPressed;
final Map<PhysicalKeyboardKey, LogicalKeyboardKey> modifierKeys =
<PhysicalKeyboardKey, LogicalKeyboardKey>{};
for (final ModifierKey key in modifiersPressed.keys) {
final Set<PhysicalKeyboardKey> mappedKeys =
_modifierKeyMap[_ModifierSidePair(key, modifiersPressed[key])];
assert(
//Line 721;
mappedKeys != null,
'Platform key support for ${Platform.operatingSystem} is '
'producing unsupported modifier combinations.');
for (final PhysicalKeyboardKey physicalModifier in mappedKeys) {
modifierKeys[physicalModifier] = _allModifiers[physicalModifier];
}
}
_allModifiersExceptFn.keys.forEach(_keysPressed.remove);
if (event.data is! RawKeyEventDataFuchsia &&
event.data is! RawKeyEventDataMacOs) {
// On Fuchsia and macOS, the Fn key is not considered a modifier key.
_keysPressed.remove(PhysicalKeyboardKey.fn);
}
_keysPressed.addAll(modifierKeys);
Btw条码扫描器在Google搜索或其他应用上运行良好
这是我的代码;
child: Container(
width: 300,
height: 35,
child: RawKeyboardListener(
focusNode: barkodFocus,
autofocus: true,
onKey: (key) {
print(key.toString());
},
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.all(8),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(5)))),
textAlign: TextAlign.left,
keyboardType: TextInputType.text,
readOnly: false,
controller: barkodController,
onSubmitted: (value) {
MusteriSiparisiRowModel satirModel =
MusteriSiparisiRowModel();
satirModel.setData(value, model).then((sonModel) {
setState(() {
barkod = value;
barkodFocus.requestFocus();
barkodController.selection = TextSelection(
baseOffset: 0,
extentOffset: barkodController.text.length);
if (sonModel != null) {
satirModel = sonModel;
bool add = true;
for (var i = 0;
i < satirlarModel.length;
i++) {
MusteriSiparisiRowModel m =
satirlarModel[i];
if (m.barkod == satirModel.barkod) {
m.setMiktar = m.getMiktar + 1;
add = false;
}
}
if (add == true) {
satirlarModel.add(satirModel);
}
} else {
scaffoldKey.currentState
.showSnackBar(SnackBar(
content: Row(
children: [
Icon(Icons.announcement),
Padding(padding: EdgeInsets.all(20)),
Text("Barkod Bulunamadı."),
],
)));
}
});
});
},
),
)),
打印(键)可用于输入,但不适用于条形码
[√] Flutter (Channel stable, 1.20.2, on Microsoft Windows [Version 10.0.18363.1016], locale tr-TR)
• Flutter version 1.20.2 at C:\src\flutter\flutter_windows_v1.12.13+hotfix.5-stable\flutter
• Framework revision bbfbf1770c (3 weeks ago), 2020-08-13 08:33:09 -0700
• Engine revision 9d5b21729f
• Dart version 2.9.1
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\DELL\AppData\Local\Android\sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.
[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[√] VS Code (version 1.48.2)
• VS Code at C:\Users\DELL\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.13.2
[√] Connected device (2 available)
• G0550 (mobile) • SAN8PSS5S5PMVEUKRCY • android-arm • Android 4.2.2 (API 17)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• No issues found!
答案 0 :(得分:1)
如果要从RawKeyboardListener获取条形码作为String,则必须将每个字符附加到现有的String。 RawKeyboardListener侦听“按下”的键,因此您不能插入整个条形码。
有一些工作示例:
String inputK = "";
FocusNode focusNode = FocusNode();
RawKeyboardListener(
autofocus: true,
focusNode: focusNode,
onKey: (RawKeyEvent event){
if(event.runtimeType.toString() == 'RawKeyDownEvent'){
String key = event.logicalKey.keyLabel;
if(key != null){
setState(() {
inputK += key;
});
}
}
},
child: Container(),
);
答案 1 :(得分:0)
这个问题有解决方案吗?我在使用 datalogic memor k 扫描仪时遇到了同样的问题。我只收到最后一次进入的事件。实际条形码编号不会触发事件。
更新... 我在扫描仪中找到了一个设置,可以将键盘输入模式从文本注入更改为按键压力,然后原始键盘侦听器开始工作:-)