Control cash drawer operations on iMin POS devices.
Add to your pubspec.yaml:
dependencies:
imin_hardware_plugin: ^1.0.0Then run:
flutter pub getimport 'package:imin_hardware_plugin/imin_hardware_plugin.dart';The plugin exports IminCashBox class for cash drawer control.
- Open cash drawer
- Check drawer status
- Configure voltage settings
bool success = await IminCashBox.open();bool isOpen = await IminCashBox.getStatus();Returns true if drawer is open, false if closed.
bool success = await IminCashBox.setVoltage(CashBoxVoltage.v12);Available voltage options:
CashBoxVoltage.v9- 9VCashBoxVoltage.v12- 12V (default)CashBoxVoltage.v24- 24V
import 'package:imin_hardware_plugin/imin_hardware_plugin.dart';
class CashBoxExample extends StatefulWidget {
@override
_CashBoxExampleState createState() => _CashBoxExampleState();
}
class _CashBoxExampleState extends State<CashBoxExample> {
bool _isOpen = false;
Timer? _statusTimer;
@override
void initState() {
super.initState();
_startStatusPolling();
}
@override
void dispose() {
_statusTimer?.cancel();
super.dispose();
}
void _startStatusPolling() {
_statusTimer = Timer.periodic(Duration(seconds: 1), (timer) {
_checkStatus();
});
}
Future<void> _checkStatus() async {
try {
final isOpen = await IminCashBox.getStatus();
setState(() => _isOpen = isOpen);
} catch (e) {
print('Error checking status: $e');
}
}
Future<void> _openDrawer() async {
try {
final success = await IminCashBox.open();
if (success) {
print('Cash drawer opened');
}
} catch (e) {
print('Error opening drawer: $e');
}
}
Future<void> _setVoltage(CashBoxVoltage voltage) async {
try {
final success = await IminCashBox.setVoltage(voltage);
if (success) {
print('Voltage set to ${voltage.value}V');
}
} catch (e) {
print('Error setting voltage: $e');
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Text('Status: ${_isOpen ? "Open" : "Closed"}'),
ElevatedButton(
onPressed: _openDrawer,
child: Text('Open Cash Drawer'),
),
ElevatedButton(
onPressed: () => _setVoltage(CashBoxVoltage.v12),
child: Text('Set 12V'),
),
],
);
}
}- Voltage must match your cash drawer specifications
- Status polling recommended for real-time updates
- Opening drawer triggers a brief pulse signal
All iMin POS devices with cash drawer port