zcs_sdk_plugin 1.2.0
zcs_sdk_plugin: ^1.2.0 copied to clipboard
A Flutter plugin for ZCS SDK integration. Provides universal dynamic printing for receipts, invoices, and documents with QR codes, dual copies, and configurable layouts. Includes printRawText for simp [...]
import 'package:flutter/material.dart';
import 'package:zcs_sdk_plugin/zcs_sdk_plugin.dart';
void main() {
runApp(const MyApp());
}
/// ZCS SDK Plugin instance
final ZcsSdkPlugin _plugin = ZcsSdkPlugin();
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ZCS SDK Plugin Demo',
theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.indigo),
home: const DemoPage(),
);
}
}
class DemoPage extends StatefulWidget {
const DemoPage({super.key});
@override
State<DemoPage> createState() => _DemoPageState();
}
class _DemoPageState extends State<DemoPage> {
String _log = '';
@override
void initState() {
super.initState();
_init();
}
Future<void> _init() async {
try {
await _plugin.getPlatformVersion();
} catch (e) {
setState(() => _log = 'Init Error: $e');
}
}
Future<void> _run(Future<dynamic> Function() call, String label) async {
setState(() => _log = '⏳ $label…');
final sw = Stopwatch()..start();
try {
final result = await call();
setState(() =>
_log = '✅ $label → ${result ?? "void"} (${sw.elapsed.inMilliseconds} ms)');
} catch (e) {
setState(() =>
_log = '❌ $label threw $e (${sw.elapsed.inMilliseconds} ms)');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('ZCS SDK Plugin Demo'),
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
ElevatedButton(
onPressed: () =>
_run(() => _plugin.initializeDevice(), 'initializeDevice'),
child: const Text('Initialize Device'),
),
ElevatedButton(
onPressed: () => _run(() => _plugin.openDevice(), 'openDevice'),
child: const Text('Open Device'),
),
ElevatedButton(
onPressed: () => _run(() => _plugin.printDynamic(
bothCopies: true,
{
'businessName': 'ZCS SDK Plugin',
'header': 'TEST RECEIPT',
'fields': {
'Date': DateTime.now().toString(),
'Message': 'Hello World',
},
'footer': 'Thank you for testing!',
}), 'printDynamic (Text)'),
child: const Text('Print Text'),
),
ElevatedButton(
onPressed: () => _run(
() => _plugin.printDynamic({
'businessName': 'ZCS SDK Plugin',
'header': 'QR CODE TEST',
'qrCodeField': 'url',
'url': 'https://example.com',
'footer': 'Scan the QR code above',
}), 'printDynamic (QR Code)'),
child: const Text('Print QR Code'),
),
ElevatedButton(
onPressed: () =>
_run(() => _plugin.getDeviceStatus(), 'getDeviceStatus'),
child: const Text('Get Device Status'),
),
ElevatedButton(
onPressed: () =>
_run(() => _plugin.getSerialNumber(), 'getSerialNumber'),
child: const Text('Get Serial Number'),
),
ElevatedButton(
onPressed: () => _run(
() => _plugin.printRawText(
'Hello, World!\nThis is a test print.\nLine 3\nLine 4\n'),
'printRawText'),
child: const Text('Print Raw Text'),
),
ElevatedButton(
onPressed: () => _run(() => _plugin.closeDevice(), 'closeDevice'),
child: const Text('Close Device'),
),
const SizedBox(height: 24),
SelectableText(
_log,
style: const TextStyle(fontFamily: 'monospace'),
),
],
),
);
}
}