scan_gun

Last updated:

0 purchases

scan_gun Image
scan_gun Images
Add to Cart

Description:

scan gun

flutter:实现扫码枪获取数据源,禁止系统键盘弹窗(不会触发键盘唤起,不会触发中文乱码) #
实现扫码枪获取数据源,禁止系统键盘弹窗。依赖 EditableText 原理,实现 flutter 端扫码能力支持。
(不会触发键盘唤起,不会触发中文乱码)
引入 #
在pubspec.yaml文件中进行引用:
dependencies:
scan_gun: ^2.0.0
copied to clipboard
使用方式: #
在 main 方法中初始化 TextInputBinding
void main() {
TextInputBinding();
runApp(const MyApp());
}
copied to clipboard
提供 ScanMonitorWidget 作为父节点,嵌套使用:
ScanMonitorWidget({
Key? key,
required ChildBuilder childBuilder,
FocusNode? scanNode,
FocusNode? textFiledNode,
required void Function(String) onSubmit,
})
copied to clipboard
参数说明:

childBuilder :

typedef ChildBuilder = Widget Function(BuildContext context),使用者自己UI作为子节点

scanNode:

非必传,如果传,可通过 scanNode 监听获取当前扫码可用状态,hasFocus 时为获取焦点

GlobalKey

非必传,如果传,可通过 'scanKey' 强制获取获取焦点,保证扫码可用,如下
scanKey.currentState?.requestKeyboard()

textFiledNode:

提供外部存在输入框键盘输入与扫码输入同时存在的场景。内部做了焦点切换能力,保证输入框焦点取消后,能马上切换成扫码枪的焦点

focusLooper:

非必传,传true可开启轮询保活扫码焦点,但需要保证当前页面堆栈只存在一个 ScanMonitorWidget

onSubmit:

接收扫码枪返回的结果
适用场景及Demo演示: #
1. 无输入框交互,获取扫码结果:
@override
Widget build(BuildContext context) {
return ScanMonitorWidget(
childBuilder: (context) {
return body();
},
onSubmit: (String result) {
print(result); //接收到扫码结果
},
);
}

copied to clipboard
2. 带输入框交互,获取扫码结果:
FocusNode textFiledNode = FocusNode();
TextEditingController controller = TextEditingController();

Widget body() {
return TextField(
focusNode: textFiledNode,
controller: controller,
);
}

@override
Widget build(BuildContext context) {
return ScanMonitorWidget(
textFiledNode: textFiledNode,
childBuilder: (context) {
return body();
},
onSubmit: (String result) {
print(result); //接收到扫码结果
},
);
}
copied to clipboard
详细使用方式可查看 example : #

技术点分析

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.