pda608_scanner_printer 0.0.1
pda608_scanner_printer: ^0.0.1 copied to clipboard
A Flutter plugin for PDA608 device thermal printer and barcode scanner.
PDA608 Scanner Printer Plugin #
A Flutter plugin for PDA608 devices to use the built-in thermal printer and barcode scanner.
Features #
- Thermal Printer: Print text with customizable formatting options
- Barcode Scanner: Scan barcodes using the device's built-in scanner
- Hardware Button Support: Trigger scanner using the device's hardware button
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
pda608_scanner_printer: ^0.0.1
Or install directly from the command line:
flutter pub add pda608_scanner_printer
Usage #
Initialize the plugin #
import 'package:pda608_scanner_printer/pda608_scanner_printer.dart';
// Initialize the printer and scanner
bool initialized = await Pda608ScannerPrinter.initializePrinter();
Print text #
// Print text with formatting options
await Pda608ScannerPrinter.printText(
text: "Hello, PDA608!",
fontSize: 1, // 0 = normal, 1 = large
alignment: 1, // 0 = left, 1 = center, 2 = right
paperWidth: 52, // Paper width in mm
isLabel: false, // Whether using label paper
tearPaper: true, // Whether to feed paper for tearing
);
Scan barcodes #
// Start barcode scanner
await Pda608ScannerPrinter.startScan();
// Listen for scan results
Pda608ScannerPrinter.onBarcodeScanned.listen((barcode) {
print('Scanned barcode: $barcode');
// Handle the barcode data
});
Using with hardware button #
The plugin automatically registers for hardware button events. Just set up a listener to receive scan results:
@override
void initState() {
super.initState();
// Listen for scan results from hardware button presses
Pda608ScannerPrinter.onBarcodeScanned.listen((barcode) {
setState(() {
myBarcodeVariable = barcode;
});
});
}
FlutterFlow Integration #
To use this plugin in FlutterFlow:
- Add the package to your FlutterFlow project dependencies
- Create a custom widget for the scanner functionality
- Use actions to handle scan results
See the documentation below for detailed FlutterFlow integration instructions.
Complete Example #
import 'package:flutter/material.dart';
import 'package:pda608_scanner_printer/pda608_scanner_printer.dart';
class PDA608Demo extends StatefulWidget {
@override
_PDA608DemoState createState() => _PDA608DemoState();
}
class _PDA608DemoState extends State<PDA608Demo> {
String _status = 'Not initialized';
bool _isInitialized = false;
String _lastScannedBarcode = '';
@override
void initState() {
super.initState();
_initializePlugin();
// Listen for scan events
Pda608ScannerPrinter.onBarcodeScanned.listen((barcode) {
setState(() {
_lastScannedBarcode = barcode;
});
});
}
Future<void> _initializePlugin() async {
bool initialized = await Pda608ScannerPrinter.initializePrinter();
setState(() {
_isInitialized = initialized;
_status = initialized ? 'Initialized' : 'Failed to initialize';
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('PDA608 Demo')),
body: Column(
children: [
Text('Status: $_status'),
Text('Last scanned: $_lastScannedBarcode'),
ElevatedButton(
onPressed: _isInitialized ? () async {
await Pda608ScannerPrinter.startScan();
} : null,
child: Text('Activate Scanner'),
),
ElevatedButton(
onPressed: _isInitialized ? () async {
await Pda608ScannerPrinter.printText(
text: 'Test Print\n$_lastScannedBarcode',
);
} : null,
child: Text('Print Last Barcode'),
),
],
),
);
}
}
Android Setup #
For Android, the plugin needs the following permissions in your AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Device Support #
This plugin is specifically designed for the PDA608 device and may not work on other devices without modifications.
License #
This plugin is available under the MIT License.