gpt4 book ai didi

android - Flutter RawKeyboardListener buggy

转载 作者:行者123 更新时间:2023-12-03 04:34:13 29 4
gpt4 key购买 nike

我有一个使用2D蓝牙扫描仪扫描条形码的应用程序。该应用程序已投入生产,并且运行良好,现在有了Flutter的最新SDK更新,一旦打开软/虚拟键盘,我用来监听扫描仪输入的RawKeyboardLister不再起作用。
在应用程序上有一些实例,用户需要键盘来输入字符,但是在他们输入字符之后,他们会转到进行更多扫描的屏幕上,侦听器仅注册RawKeyUpEvent,而不再注册RawKeyDownEvent
这是我的代码:

class ScannerFragment extends StatefulWidget {
final Widget child;
final StreamController scanController;

ScannerFragment(
{Key key, @required this.child, @required this.scanController})
: super(key: key);

@override
_ScannerFragmentState createState() => _ScannerFragmentState();
}

class _ScannerFragmentState extends State<ScannerFragment> {
final FocusNode focusNode = new FocusNode();

final List<String> scannedCharacters = [];

@override
Widget build(BuildContext context) {
return Consumer<BaseProvider>(
builder: (BuildContext _, BaseProvider provider, Widget __) {
if (!provider.keyboardMustComeToView)
return _buildRawKeyboardListener();

return widget.child;
},
);
}

Widget _buildRawKeyboardListener() {
return RawKeyboardListener(
focusNode: focusNode,
onKey: _handleKey,
child: widget.child,
);
}

void _handleKey(RawKeyEvent key) {
var x = key.character;
var u = key.logicalKey;
var y = locator<BaseProvider>().keyboardMustComeToView;
print("${key.character}");
if (key.runtimeType.toString() == 'RawKeyDownEvent') {
RawKeyEventDataAndroid data = key.data as RawKeyEventDataAndroid;
//keycode of key event (66 is return)
if (data.keyCode == 66 || data.flags == 136) {
locator<DirectechProvider>().setProcessingScan = false;
print("terminate: ${scannedCharacters.join()}");
widget.scanController.add(scannedCharacters.join());
widget.scanController.done;
scannedCharacters.clear();
return;
}
if (key.character != null) {
if (!locator<DirectechProvider>().processingScan)
locator<DirectechProvider>().setProcessingScan = true;
scannedCharacters.add(key.character);
}
}
}


@override
void didChangeDependencies() {
super.didChangeDependencies();
FocusScope.of(context).requestFocus(focusNode);
}

@override
void dispose() {
focusNode.dispose();
super.dispose();
}
这是我 flutter 的医生:
[✓] Flutter (Channel stable, 1.22.0, on Mac OS X 10.14.6 18G6020, locale en-ZA)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
[✓] Android Studio (version 4.0)
[!] VS Code (version 1.48.2)
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (1 available)
- 编辑 -
处理具有文本字段的屏幕后,然后返回没有文本字段的扫描屏幕。这是我面临的问题,屏幕底部有一个小的软输入内容,它捕获了我实际扫描的内容,但键盘监听器却读取了不正确的内容。
enter image description here
N.B.当我最小化应用程序并再次打开它时,扫描工作正常。

最佳答案

在什么版本的Flutter上它停止工作了?
现在,我建议回滚到该版本。这将使您能够持续进行生产开发,并且用户可以继续接收更新。
编写以下命令:

flutter downgrade "version_number"
flutter clean
但是,从长远来看,您能否发布用于接收来自蓝牙扫描器流的软件包名称?
[编辑]
然后尝试以下命令:
flutter version 1.17.4
然后,当它要求您确认是否要降级时,请按
完成后,运行:
flutter clean

关于android - Flutter RawKeyboardListener buggy ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64384796/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com