talabi_printer 0.1.1 copy "talabi_printer: ^0.1.1" to clipboard
talabi_printer: ^0.1.1 copied to clipboard

outdated

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';

      await _talabiPrinterPlugin.setGray(6);
      await _talabiPrinterPlugin.addText('Talabi is printing');
      await _talabiPrinterPlugin.addTextLeftRight('Left Text', 'Right Text', 2, true);
      await _talabiPrinterPlugin.addTextLeftCenterRight('Left Text', 'Center Text', 'Right Text', 0, false);
      //await _talabiPrinterPlugin.addBarCode('Talabi Orders');
      //await _talabiPrinterPlugin.addQrCode('Talabi Orders LTD');
      //await _talabiPrinterPlugin.addImage(await readAssetBytes('assets/talabi.png'));
      await _talabiPrinterPlugin.feedLine(3);

      await _talabiPrinterPlugin.startPrint();
    } on PlatformException catch(e) {
      _error = '${e.code}: ${e.message ?? ''} ${e.details ?? ''}';
    }

    // 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'),
            ],
          ),
        ),
      ),
    );
  }
  
  Future<Uint8List> readAssetBytes(String asset) async {
    final data =  await rootBundle.load(asset);
    return data.buffer.asUint8List();
  }
}
1
likes
0
points
30
downloads

Publisher

unverified uploader

Weekly Downloads

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 functionality in Flutter applications.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on talabi_printer

Packages that implement talabi_printer