【亲测免费】 蓝牙打印神器:BluetoothPrint 插件
2026-01-18 09:50:24作者:伍霜盼Ellen
在移动应用开发的世界里,Flutter 以其高效和跨平台特性赢得了众多开发者的青睐。今天,我们要介绍的是一款专为 Flutter 设计的蓝牙打印插件——BluetoothPrint,它将帮助你轻松构建适用于 iOS 和 Android 的蓝牙热敏打印应用。
项目介绍
BluetoothPrint 是一个为 Flutter 设计的蓝牙插件,支持多种热敏打印机,如 Gprinter pt-280、pt-380、gp-1324、gp-2120 等。该插件不仅支持基本的蓝牙设备扫描、连接、断开和状态监听,还提供了丰富的打印功能,包括文本、图像、二维码和条形码的打印。
项目技术分析
BluetoothPrint 插件充分利用了 Flutter 的跨平台优势,通过统一的 API 接口,实现了在 iOS 和 Android 平台上的无缝操作。其核心功能包括:
- 扫描:启动蓝牙低功耗设备扫描。
- 连接:与设备建立连接。
- 断开:取消与设备的连接。
- 状态监听:实时监听蓝牙设备的状态变化。
- 打印功能:支持文本、图像、二维码和条形码的打印,并支持布局调整。
项目及技术应用场景
BluetoothPrint 插件适用于多种场景,特别是需要蓝牙打印功能的应用,如零售、餐饮、物流等行业。无论是打印订单、收据,还是标签,BluetoothPrint 都能提供稳定可靠的打印服务。
项目特点
- 跨平台支持:完美兼容 iOS 和 Android 平台。
- 丰富的打印功能:支持文本、图像、二维码和条形码的打印。
- 易于集成:通过简单的配置和调用,即可在 Flutter 项目中集成蓝牙打印功能。
- 持续更新:项目持续维护,不断增加新功能和改进现有功能。
使用指南
添加依赖
在你的 pubspec.yaml 文件中添加以下依赖:
dependencies:
flutter:
sdk: flutter
bluetooth_print:
初始化实例
import 'package:bluetooth_print/bluetooth_print.dart';
import 'package:bluetooth_print/bluetooth_print_model.dart';
BluetoothPrint bluetoothPrint = BluetoothPrint.instance;
扫描设备
bluetoothPrint.startScan(timeout: Duration(seconds: 4));
StreamBuilder<List<BluetoothDevice>>(
stream: bluetoothPrint.scanResults,
initialData: [],
builder: (c, snapshot) => Column(
children: snapshot.data.map((d) => ListTile(
title: Text(d.name??''),
subtitle: Text(d.address),
onTap: () async {
setState(() {
_device = d;
});
},
trailing: _device!=null && _device.address == d.address?Icon(
Icons.check,
color: Colors.green,
):null,
)).toList(),
),
),
连接设备
await bluetoothPrint.connect(_device);
断开连接
await bluetoothPrint.disconnect();
监听状态
bluetoothPrint.state.listen((state) {
print('cur device status: $state');
switch (state) {
case BluetoothPrint.CONNECTED:
setState(() {
_connected = true;
});
break;
case BluetoothPrint.DISCONNECTED:
setState(() {
_connected = false;
});
break;
default:
break;
}
});
打印示例
Map<String, dynamic> config = Map();
List<LineText> list = List();
list.add(LineText(type: LineText.TYPE_TEXT, content: 'A Title', weight: 1, align: LineText.ALIGN_CENTER,linefeed: 1));
list.add(LineText(type: LineText.TYPE_TEXT, content: 'this is conent left', weight: 0, align: LineText.ALIGN_LEFT,linefeed: 1));
list.add(LineText(type: LineText
登录后查看全文
热门项目推荐
相关项目推荐
atomcodeClaude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed. Get StartedRust0218
cann-learning-hubCANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。Jupyter Notebook0139
uni-appA cross-platform framework using Vue.jsJavaScript09
GLM-5.2智谱开源 GLM-5.2,这是针对长文本任务的最新旗舰模型。相较于前代产品 GLM-5.1,它在长文本任务处理能力上实现了显著飞跃,并且首次在稳定的 100 万 token 上下文中提供这一能力。Jinja00
SwanLab⚡️SwanLab - an open-source, modern-design AI training tracking and visualization tool. Supports Cloud / Self-hosted use. Integrated with PyTorch / Transformers / LLaMA Factory / veRL/ Swift / Ultralytics / MMEngine / Keras etc.Python00
tiny-universe《大模型白盒子构建指南》:一个全手搓的Tiny-UniverseJupyter Notebook03
项目优选
收起
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
471
465
deepin linux kernel
C
32
16
Claude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed.
Get Started
Rust
2.09 K
218
本项目是CANN提供的神经网络类计算算子库,实现网络在NPU上加速计算。
C++
700
1.4 K
暂无描述
Dockerfile
780
5.08 K
Ascend Extension for PyTorch
Python
758
968
本仓库是 Flutter SDK 与 Flutter Engine 的 OpenHarmony 适配版本,由 CPF-Flutter 团队维护。开发者可使用熟悉的 Flutter 技术栈开发 OpenHarmony 应用,3.35.7 及以后的适配版本可基于本仓库源码构建支持 OpenHarmony 的 Flutter Engine。
Dart
1.04 K
271
本项目是CANN提供的transformer类大模型算子库,实现网络在NPU上加速计算。
C++
880
2.03 K
MindQuantum is a general software library supporting the development of applications for quantum computation.
Python
183
111
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
1.11 K
682