talabi_printer 0.1.0
talabi_printer: ^0.1.0 copied to clipboard
A Flutter plugin for sending printing commands to a Urovo i9100 thermal printer. This plugin allows seamless integration with the Urovo i9100 printer to send commands and facilitate printing functiona [...]
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:talabi_printer/talabi_printer.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
late String _printerStatus;
String _error = '';
final _talabiPrinterPlugin = TalabiPrinter();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _talabiPrinterPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
try {
final s = await _talabiPrinterPlugin.getStatus();
_printerStatus = s != null ? '$s' : 'Unknown printer status';
} on PlatformException {
_printerStatus = 'Failed to get printer status.';
}
try {
await _talabiPrinterPlugin.addText('Talabi is printing');
await _talabiPrinterPlugin.addText('Talabi is about to start');
await _talabiPrinterPlugin.addText('ASTA LA VISTA... HERE WE GO, BABY!!!');
try {
await _talabiPrinterPlugin.startPrint();
} on PlatformException catch (e) {
_error = 'Start print failed: ${e.toString()}';
}
} on PlatformException catch (e) {
_error = 'Faild to print a text: ${e.toString()}';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text('Running on: $_platformVersion\n'),
Text('Printer status: $_printerStatus\n'),
if (_error.isNotEmpty) Text('Printer error: $_error\n'),
],
),
),
),
);
}
}