Flutter霍尼韦尔移动SDK集成插件honeywell_mobility_sdk的使用
Flutter霍尼韦尔移动SDK集成插件honeywell_mobility_sdk的使用
霍尼韦尔移动SDK适用于Flutter
霍尼韦尔移动SDK包含一系列工具和资源,这些工具和资源利用了霍尼韦尔安卓移动计算机特有的功能,例如条形码扫描。
如何霍尼韦尔移动计算机简化条形码扫描?
霍尼韦尔高度准确且适应性强的条形码读取器提供了卓越的条形码扫描性能和数据采集。霍尼韦尔的条形码读取器可以适应多种企业工作流程,并提供多种配置。无论它们是位于销售点、安装在仓库传送带上方还是安装在墙上以快速访问,我们的直观条形码读取器为企业提供了自由度,使其能够根据其关键业务需求进行部署。霍尼韦尔的条形码读取器具有行业领先的扫描性能,可以迅速而准确地读取甚至损坏的条形码,从而保持工作流程的优化和按时进行。霍尼韦尔的条形码扫描器具备高性能的条形码读取器,提供出色的数据收集和条形码扫描能力。它们是独特的且灵活的,适用于不同的组织工作流程。此外,它们出色的扫描能力并不会使系统变得过于复杂。它们可以在各种业务应用中运行,包括资产和库存跟踪。
支持的设备
- CK65手持电脑
- CN80手持电脑
- CN80G手持电脑
- CT40手持电脑
- CT40 XP手持电脑
- CT45 / CT45 XP
- CT60 XP手持电脑
- Dolphin CT60手持电脑
- Honeywell Dolphin 75e
- RT10坚固型平板电脑
- ScanPal EDA50手持电脑
- ScanPal EDA50K手持电脑
- ScanPal EDA70手持电脑
- ScanPal EDA71企业平板电脑
- Thor VM1A车载电脑
- Thor VM3A车载电脑
设置
在 android/app/build.gradle
文件中添加以下行:
dependencies {
...
implementation 'com.github.AcmeSoftwareLLC:hwmsdk-android:main-SNAPSHOT' // 添加此行
}
使用
final barcodeReader = await HoneywellMobilitySdk.createBarcodeReader(
onRead: (event) {
print(event.barcodeData); // 打印扫描到的条形码数据
},
onFailure: (event) {
print(event.timestamp); // 打印失败事件的时间戳
},
onTrigger: (event) {
print(event.state); // 打印触发状态
},
);
barcodeReader.claim(); // 一旦声明了条形码读取器,回调就会生效。
注意:如果设备不支持条形码扫描,则条形码读取器将为null。
软件触发扫描
// true 表示触发按钮被按下,false 表示触发按钮被释放
barcodeReader.softwareTrigger(true|false);
处理生命周期变化
[@override](/user/override)
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
barcodeReader.claim();
break;
case AppLifecycleState.inactive:
case AppLifecycleState.paused:
barcodeReader.release();
break;
case AppLifecycleState.detached:
barcodeReader.close();
break;
}
}
完整示例Demo
以下是完整的示例代码,展示了如何在Flutter应用中集成霍尼韦尔移动SDK。
主文件 (lib/main.dart
)
import 'package:flutter/material.dart';
import 'package/flutter/services.dart';
import 'package:honeywell_mobility_sdk/honeywell_mobility_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(colorSchemeSeed: Colors.orange),
home: Builder(
builder: (context) {
return Scaffold(
appBar: AppBar(
title: const Text('Honeywell Mobility SDK'),
),
body: Center(
child: FilledButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const ScannerPage()),
),
child: const Text('Open Scanner Page'),
),
),
);
},
),
);
}
}
enum ScannerAction {
none,
claim,
startScanning,
stopScanning,
release,
}
class ScannerPage extends StatefulWidget {
const ScannerPage({super.key});
[@override](/user/override)
State<ScannerPage> createState() => _ScannerPageState();
}
class _ScannerPageState extends State<ScannerPage> with WidgetsBindingObserver {
BarcodeReader? _barcodeReader;
String? data;
String? error;
String? trigger;
ScannerAction action = ScannerAction.none;
[@override](/user/override)
void initState() {
super.initState();
_initReader();
WidgetsBinding.instance.addObserver(this);
}
Future<void> _initReader() async {
_barcodeReader = await HoneywellMobilitySdk.createBarcodeReader(
onRead: (event) {
data = '${event.barcodeData} (${event.codeType})';
error = null;
if (mounted) setState(() {});
},
onFailure: (event) {
error = 'Could not read barcode.';
data = null;
if (mounted) setState(() {});
},
onTrigger: (event) {
trigger = event.state ? 'Pressed' : 'Released';
if (mounted) setState(() {});
},
);
}
[@override](/user/override)
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
_barcodeReader?.claim();
break;
case AppLifecycleState.inactive:
case AppLifecycleState.paused:
_barcodeReader?.release();
break;
case AppLifecycleState.detached:
_barcodeReader?.close();
break;
}
}
[@override](/user/override)
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_barcodeReader?.close();
super.dispose();
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Scanner Page'),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(2),
child: action == ScannerAction.startScanning
? const LinearProgressIndicator(minHeight: 2)
: const SizedBox.shrink(),
),
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_ResultCard(data: data, trigger: trigger, error: error),
const SizedBox(height: 16),
DropdownMenu(
leadingIcon: const Icon(Icons.barcode_reader),
label: const Text('Scan Mode'),
initialSelection: TriggerScanMode.oneShot,
onSelected: (mode) {
if (mode != null) {
_invoke(
(reader) => reader.setProperty(
BarcodeReaderProperty.trigger.scanMode(mode),
),
);
}
},
dropdownMenuEntries: [
for (final mode in TriggerScanMode.values)
DropdownMenuEntry(value: mode, label: mode.name),
],
),
const SizedBox(height: 16),
_Button(
label: 'Claim',
enableFor: const [ScannerAction.none, ScannerAction.release],
action: action,
onPressed: () async {
final supported = await _invoke((reader) => reader.claim());
if (supported) _updateAction(ScannerAction.claim);
},
),
_Button(
label: 'Start Scanning',
enableFor: const [
ScannerAction.claim,
ScannerAction.stopScanning
],
action: action,
onPressed: () async {
await _invoke((reader) => reader.softwareTrigger(true));
_updateAction(ScannerAction.startScanning);
},
),
_Button(
label: 'Pause Scanning',
enableFor: const [ScannerAction.startScanning],
action: action,
onPressed: () async {
await _invoke((reader) => reader.softwareTrigger(false));
_updateAction(ScannerAction.stopScanning);
},
),
_Button(
label: 'Release',
enableFor: const [
ScannerAction.claim,
ScannerAction.startScanning,
ScannerAction.stopScanning
],
action: action,
onPressed: () async {
await _invoke((reader) => reader.release());
_updateAction(ScannerAction.release);
},
),
FilledButton(
onPressed: () => Navigator.pop(context),
child: const Text('Close'),
),
],
),
),
);
}
void _updateAction(ScannerAction action) {
this.action = action;
setState(() {});
}
Future<bool> _invoke(
Future<void> Function(BarcodeReader reader) callback,
) async {
if (_barcodeReader == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Unsupported device.')),
);
return false;
}
try {
await callback(_barcodeReader!);
} on PlatformException catch (e) {
error = '${e.message} (${e.code}) (${e.details})';
if (mounted) setState(() {});
}
return true;
}
}
class _ResultCard extends StatelessWidget {
const _ResultCard({
required this.data,
required this.trigger,
required this.error,
});
final String? data;
final String? trigger;
final String? error;
[@override](/user/override)
Widget build(BuildContext context) {
return Card(
color: data == null ? Colors.red.shade300 : Colors.green.shade300,
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
Text(
'Data: $data',
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 8),
Text(
'Trigger: $trigger',
style: Theme.of(context).textTheme.labelLarge,
),
const SizedBox(height: 8),
Text(
'Error At: $error',
style: Theme.of(context).textTheme.labelMedium,
),
],
),
),
);
}
}
class _Button extends StatelessWidget {
const _Button({
required this.label,
required this.enableFor,
required this.action,
required this.onPressed,
});
final String label;
final List<ScannerAction> enableFor;
final ScannerAction action;
final VoidCallback onPressed;
[@override](/user/override)
Widget build(BuildContext context) {
return FilledButton(
onPressed: _activeOn(enableFor) ? onPressed : null,
child: Text(label),
);
}
bool _activeOn(List<ScannerAction> actions) {
return actions.contains(action);
}
}
更多关于Flutter霍尼韦尔移动SDK集成插件honeywell_mobility_sdk的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter霍尼韦尔移动SDK集成插件honeywell_mobility_sdk的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是一个关于如何在Flutter项目中集成和使用honeywell_mobility_sdk
插件的示例代码。请确保你已经按照霍尼韦尔移动SDK的官方文档完成了必要的准备工作,比如获取SDK许可、下载SDK文件等。
1. 添加依赖
首先,在你的pubspec.yaml
文件中添加honeywell_mobility_sdk
依赖:
dependencies:
flutter:
sdk: flutter
honeywell_mobility_sdk: ^x.y.z # 请替换为最新版本号
然后运行flutter pub get
来安装依赖。
2. 配置Android和iOS
根据霍尼韦尔移动SDK的要求,你可能需要在AndroidManifest.xml
和Info.plist
中添加一些权限和配置。具体步骤请参考霍尼韦尔移动SDK的官方文档。
3. 初始化SDK
在你的Flutter应用中,初始化霍尼韦尔移动SDK。这通常在你的主页面或应用启动时完成。
import 'package:flutter/material.dart';
import 'package:honeywell_mobility_sdk/honeywell_mobility_sdk.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late HoneywellMobilitySDK _sdk;
@override
void initState() {
super.initState();
// 初始化SDK
_initSDK();
}
Future<void> _initSDK() async {
try {
_sdk = await HoneywellMobilitySDK.instance;
// 检查SDK是否可用
bool isAvailable = await _sdk.isAvailable();
print("SDK Available: $isAvailable");
// 如果需要,可以进一步配置SDK,例如设置扫描参数等
// await _sdk.configureScanner(...);
} catch (e) {
print("SDK Initialization Error: $e");
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Honeywell Mobility SDK Example'),
),
body: Center(
child: ElevatedButton(
onPressed: () async {
// 触发扫描操作
try {
String scanResult = await _sdk.startScanner();
print("Scan Result: $scanResult");
} catch (e) {
print("Scan Error: $e");
}
},
child: Text('Start Scanner'),
),
),
),
);
}
}
4. 调用SDK功能
在上述代码中,我们展示了如何初始化SDK以及触发扫描操作。具体功能调用(如配置扫描器、读取条码等)将依据霍尼韦尔移动SDK提供的API进行。
注意事项
- 确保你已经正确配置了霍尼韦尔移动SDK所需的权限和依赖项。
- 仔细阅读并遵循霍尼韦尔移动SDK的官方文档,以确保正确集成和使用。
- 由于SDK版本更新可能会导致API变化,因此请始终参考最新版本的官方文档。
以上代码提供了一个基本的框架,用于在Flutter应用中集成和使用霍尼韦尔移动SDK。根据具体需求,你可能需要进一步调整和扩展代码。