zebra_printer 0.2.4
zebra_printer: ^0.2.4 copied to clipboard
Flutter management package for Zebra printers. Uses Zebra Link-OS SDK for Bluetooth & Network discovery, ZPL printing, and printer management.
Changelog #
0.2.4 Connection Validity Check & Broken Pipe Fix π‘οΈ #
-
Critical Bug Fix
- Fixed "Broken pipe" error when calling
sendZplToPrinter()aftergetPrinterInfo() - Added connection validity check before reusing
activeConnection - Resolved socket state corruption issue caused by SGD commands
- Fixed "Broken pipe" error when calling
-
Connection Management Improvements
activeConnectionnow verified withisConnected()before use- Automatic connection recovery when active connection is closed
- Stale connections automatically detected and recreated
- All three methods now include connection validity checks:
sendZplToPrinter()getPrinterInfo()checkPrinterStatus()
-
Reliability Enhancements
- Connection state validation in all reuse scenarios
- Graceful handling of closed connections
- 10-second connection cache still active for fast reconnection
- Better error logging for connection state issues
-
Technical Details
- Added
isConnected()check before usingactiveConnection - Automatic cleanup of stale connection references
- Connection state verified in real-time, not just by reference
- Fast path (500ms) for recent connections still applies
- Added
-
Flow Example
connect() β getPrinterInfo() β sendZplToPrinter() β No "Broken pipe" error β Automatic recovery if connection breaks β Fast execution with connection cache
Upgrade Impact: Non-breaking - Critical reliability fix for production use.
0.2.3 Connection Reuse & Reliability Fix π§ #
-
Bug Fixes
- Fixed socket timeout error when calling
getPrinterInfo()orcheckPrinterStatus()afterconnect() - Resolved "read failed, socket might closed or timeout" error caused by multiple simultaneous connections
- Fixed socket timeout error when calling
-
Performance Improvements
getPrinterInfo()now reuses active connection when available (300ms vs 800ms)checkPrinterStatus()now reuses active connection when available (300ms vs 800ms)- Reduced connection overhead for consecutive info/status queries
-
New Features
- Smart connection management: automatically detects and reuses active connections
- Connection state awareness: methods intelligently switch between active and temporary connections
- Enhanced logging for connection lifecycle debugging
-
Technical Details
- Added
shouldCloseConnectionflag to prevent closing active connections - Both
getPrinterInfo()andcheckPrinterStatus()now check foractiveConnection - Temporary connections created only when no active connection exists or address differs
- Connection stabilization: 300ms for active connections, 800ms for new connections
- Added
-
Developer Experience
- Detailed debug logging added (Dart + Android) for troubleshooting
- Better error messages with full exception stack traces
- Null-safe parameter validation
Upgrade Impact: Non-breaking - existing code continues to work with improved reliability and performance.
0.2.2 PrinterInfo Model Update π― #
-
Breaking Changes
getPrinterInfo()now returnsPrinterInfomodel instead of rawString
-
New Features
- Added
PrinterInfomodel class with structured printer informationmodel: Printer model name (e.g., "ZD421")serialNumber: Printer serial numberfirmware: Firmware versionlanguage: PrinterLanguage enum (ZPL/CPCL/Unknown)rawInfo: Original raw string (for debugging)
- Added
PrinterLanguageenum for type-safe language detection - Type-safe access to printer information with autocomplete support
- Added
-
Improvements
- Better type safety for printer information
- Improved example app with formatted printer info dialog
- Added helper methods:
toCompactString(),toJson(),fromMap()
-
Developer Experience
- IDE autocomplete support for printer info fields
- Null-safe implementation
- Clean, structured data instead of string parsing
- Better testability
0.2.1 Documentation Update π #
- Documentation Improvements
- Moved Architecture & SDK Usage section before Installation for better flow
- Removed detailed method comparison tables for cleaner documentation
- Removed API Reference section (redundant with inline documentation)
- Kept essential comparison tables: Implementation Comparison + Why Two Managers
- README.md reduced from 18 KB to 14 KB for faster loading
0.2.0 Production Ready Release π #
Major Features & Improvements #
π― PrinterManager - Full Zebra SDK Integration
-
Discovery System
- Renamed
discoverPrinters()βstartDiscovery()for clarity - Added Zebra SDK-powered discovery (
BluetoothDiscoverer,NetworkDiscoverer) - Supports 'bluetooth', 'network', and 'both' discovery modes
- Real-time callbacks:
onPrinterFound,onDiscoveryFinished - Discovery optimization to prevent premature finish callbacks
- Renamed
-
Connection Management
connect()now returnsFuture<bool>(previouslyFuture<Map<String, dynamic>>)disconnect()now returnsFuture<bool>(previouslyFuture<String>)- Added persistent connection support with
activeConnectiontracking - Enhanced
isConnected()to check specific address or general status - Connection state monitoring via
onConnectionStateChangedcallback
-
New Methods
getPairedPrinters()- ReturnsFuture<List<BluetoothDevice>>(all paired devices)unpairPrinter(address)- Removes device pairing via Android Bluetooth API- Uses Android API for pairing operations (Zebra SDK limitation)
-
Print Optimization β‘
- Smart Connection Handling: Uses active connection when available, creates temporary otherwise
- Connection Caching: 10-second cache for repeated prints to same printer
- First-Print Fix: Robust readiness check with retry mechanism (3 attempts: 2s, 1s, 800ms)
- Fast Path: 300ms delay for active connections, 500ms for cached connections
- Lightweight Verification: Uses
SGD.GET("device.friendly_name")instead of heavygetCurrentStatus() - Eliminated "socket closed or timeout" errors on first print
- Optimized for rapid successive printing (warehouse/retail scenarios)
π§ BluetoothManager - Generic Bluetooth
- Added
unpairDevice(address)method for consistency - Automatic disconnection before unpairing
- Maintains 100% Android Bluetooth API implementation
π± Example App - Professional UI
- Dual-tab interface: "Zebra SDK" and "Bluetooth" tabs
- Shows discovered printers with type indicators (Bluetooth/Network)
- Paired device management with "Paired" button
- Unpair functionality with delete icon on each device
- Connection status indicators (green checkmark)
- Modern Material Design 3 with color-coded sections
- Comprehensive button set: Discover, Paired, Print, Status, Info, Disconnect
Android Native Improvements #
PrinterManager.java
- Architecture: 99% Zebra Link-OS SDK, 1% Android API (for pairing only)
- Added
Context,Handler,MethodChannelfor better lifecycle management - Implemented
ExecutorServicefor background operations - Connection caching with
lastConnectionTimemap (10s duration) - Multi-retry connection readiness check in
sendZplToPrinter() - All methods use Zebra SDK except
getPairedPrinters()andunpairPrinter()
BluetoothManager.java
- Architecture: 100% Android Bluetooth API
- Added
unpairDevice()method using reflection - Automatic disconnection before unpair operation
Dependencies & Permissions
- Added Jackson dependencies:
jackson-core,jackson-databind,jackson-annotations - Added Apache Commons:
commons-lang3 - Network permissions:
INTERNET,ACCESS_NETWORK_STATE,ACCESS_WIFI_STATE,CHANGE_WIFI_STATE,CHANGE_WIFI_MULTICAST_STATE - Updated Bluetooth permissions for Android 12+ compatibility
- NDK version set to
27.0.12077973
Documentation π #
README.md
- New Section: "ποΈ Architecture & SDK Usage" with detailed comparison tables
- Android Native Implementation Comparison table
- Detailed Method Comparison for both managers
- Shows which methods use Zebra SDK vs Android Bluetooth API
- Explains why certain methods must use Android API
- Updated all API method signatures
- Added comprehensive code examples
- ZPL examples for barcodes, QR codes, receipts
New Files
- API comparison tables integrated into README
- All method signatures updated to reflect v0.2.0 changes
Breaking Changes β οΈ #
-
Method Renames
discoverPrinters()βstartDiscovery()
-
Return Type Changes
connect():Future<Map<String, dynamic>>βFuture<bool>disconnect():Future<String>βFuture<bool>getPairedPrinters():Future<List<Map<String, dynamic>>>βFuture<List<BluetoothDevice>>
-
Method Behavior Changes
sendZplToPrinter(): Now uses active connection when available, creates temporary otherwisedisconnect(): Now accepts optional address parameter
Bug Fixes π #
- Fixed: "socket closed or timeout" error on first print after connect
- Fixed: Connection readiness timing issues
- Fixed: Discovery callbacks firing prematurely with "both" mode
- Fixed: Missing imports (
PrinterStatus, Jackson classes) - Fixed: Thread.sleep() unreported exceptions
- Fixed: NDK version mismatch warnings
Performance Enhancements π #
- 10x faster successive prints with connection caching (10s window)
- Active connection reuse reduces latency from ~2s to ~300ms
- Smart retry logic ensures first print reliability
- Lightweight status checks using SGD instead of full printer status
Testing & Quality #
- Comprehensive debug logging added throughout
- Example app demonstrates all features
- Tested with rapid successive printing scenarios
- Connection pooling verified for warehouse environments
0.1.9 #
- Removed iOS platform support
- Package now supports Android platform only
- Cleaned up iOS-related code and dependencies
- Translated example app to English
- Updated documentation to reflect Android-only support
0.1.8 #
- Previous iOS-related changes (now removed)
0.1.7 #
- Translated documentation to English
- Updated package documentation
0.1.6 #
- Package update
- Performance improvements
0.1.5 #
- Added missing files
- Updated configuration files
0.1.4 #
- Improved code format in example app
0.1.3 #
- Added example app
- Improved package structure
0.1.2 #
- Updated README file
- Added pub.flutter-io.cn badges
- Updated version information
0.1.1 #
- Updated GitHub repository information
- Fixed package name (com.example -> com.sameetdmr)
0.1.0 #
- Initial release
- Core features:
- Scan and discover Bluetooth devices
- Pair and unpair with Bluetooth devices
- Connect and disconnect from Zebra printers
- Send ZPL code to printers
- Check printer status
- Get printer information
- Enum usage:
- BluetoothDeviceType
- BluetoothBondState
- BluetoothConnectionState
- BluetoothScanState
- PrinterConnectionState
- PaperState
- HeadState
- PauseState
- Advanced Bluetooth connection management
- Zebra Link-OS SDK integration for Android