This package is a wrapper for the sunmi_printer_plus, sunmi_scanner, image, sumup, and qrcode_barcode_scanner packages. It provides a way to import these packages conditionally based on the platform. This is useful for when you want to use these packages on Android, while also deploying the same code to the web. Specifically made for usage with FlutterFlow, since FlutterFlow does not support conditional imports.
Features
This package provides:
- Conditional imports for the sunmi_printer_plus package for receipt printing
- Conditional imports for the sunmi_scanner package for barcode scanning
- Conditional imports for the qrcode_barcode_scanner package for external scanner devices
- Image processing with transparency support and aspect ratio preservation (using the image package)
- SumUp payment integration for processing card payments
- Cross-platform compatibility for web and Android
Getting started
Add the following to your pubspec.yaml file:
dependencies:
sunmiconditionalimports: ^0.2.5
Usage
import 'package:sunmiconditionalimports/sunmiconditionalimports.dart';
DO NOT import the other files directly, as they are not intended to be used directly.
Use the following classes from this package:
Printing
SunmiPrinter- example:SunmiPrinter.printText('Hello World')SunmiPrintAlign- example:SunmiPrintAlign.center()SunmiFontSize- example:SunmiFontSize.md()ColumnMaker- example:ColumnMaker(text: 'Hello World', width: 10, align: SunmiPrintAlign.center())Bitmap- example:Bitmap.fromProvider(NetworkImage('https://example.com/image.png'), 100)
Barcode Scanning
SunmiScanner- For Sunmi device barcode scanning functionalityQRCodeScanner- For external QR code and barcode scanner devices
QRCodeScanner Example
// Initialize the QR code scanner with a callback
QRCodeScanner.initialize(
onScannedCallback: (String scannedValue) {
print('Scanned code: $scannedValue');
// Process the scanned value here
},
);
// Check if scanner is initialized
final isInitialized = QRCodeScanner.isInitialized();
print('Scanner initialized: $isInitialized');
// Dispose the scanner when done (e.g., in dispose method)
@override
void dispose() {
QRCodeScanner.dispose();
super.dispose();
}
Payment Processing
Sumup- For SumUp payment processingSumupPayment- For creating payment requests
SumUp Payment Example
// Initialize SumUp with your affiliate key
final initResult = await Sumup.init('YOUR_AFFILIATE_KEY');
// Login to SumUp
final loginResult = await Sumup.login();
if (!loginResult.status) {
print('Login failed: ${loginResult.message}');
return;
}
// Create a payment
final payment = SumupPayment(
title: 'Purchase',
total: 19.99,
currency: 'EUR',
saleItemsCount: 1,
skipSuccessScreen: false,
);
// Create a payment request
final paymentRequest = SumupPaymentRequest(payment);
// Process the payment
final result = await Sumup.checkout(paymentRequest);
// Check the result
if (result.status) {
print('Payment successful!');
print('Transaction code: ${result.transactionCode}');
print('Card type: ${result.cardType}');
} else {
print('Payment failed: ${result.message}');
}
SunmiScanner Example
// Check if scanner is available
final isAvailable = await SunmiScanner.isScannerAvailable();
// Get scanner model
final scannerModel = await SunmiScanner.getScannerModel();
// Start scanning
await SunmiScanner.scan();
// Listen for scanned barcodes
SunmiScanner.onBarcodeScanned().listen((barcode) {
print('Scanned barcode: $barcode');
});
// Stop scanning when done
await SunmiScanner.stop();
Libraries
- bitmapimports_android
- bitmapimports_exports
- bitmapimports_web
- qrcodescannerimports_android
- qrcodescannerimports_exports
- qrcodescannerimports_web
- sumupimports_android
- sumupimports_exports
- sumupimports_web
- sunmiconditionalimports
- sunmiprinterimports_android
- sunmiprinterimports_exports
- sunmiprinterimports_web
- sunmiscannerimports_android
- sunmiscannerimports_exports
- sunmiscannerimports_web