telpo_m8 0.0.9 copy "telpo_m8: ^0.0.9" to clipboard
telpo_m8: ^0.0.9 copied to clipboard

PlatformAndroid

A Flutter plugin for interacting with Telpo M8 devices, allowing for operations such as displaying images on LCD, generating QR codes, and printing with a thermal printer.

example/lib/main.dart

import 'dart:io';
import 'package:http/http.dart' as http;

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:telpo_m8/telpo_m8.dart';

void main() {
  runApp(const MaterialApp(home: MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _versionNumber = 'Unknown';
  String _qrCodeResult = 'Unknown';

  final _telpoM8Plugin = TelpoM8();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    String versionNumber = "";
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      // platformVersion = await _telpoM8Plugin.getPlatformVersion() ??
      'Unknown platform version';
      // int versionNumber = await _telpoM8Plugin.getVersionNumber() ?? 0;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // 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;
      // _versionNumber = versionNumber;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Telpo M8 Plugin example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              // Text(
              //     'Running on: $_platformVersion\n Version Number: $_versionNumber\n'),
              // TextButton(
              //   child: const Text('Read QR Code'),
              //   onPressed: () async {
              //     String? qrCodeResult =
              //         await TelpoM8().readQRCode('/path/to/my_image.jpg');
              //     setState(() {
              //       _qrCodeResult = qrCodeResult!;
              //     });
              //   },
              // ),
              // Text('QR Code Result: $_qrCodeResult'),
              // TextButton(
              //   child: const Text('Generate QR Code'),
              //   onPressed: () {
              //     final BuildContext currentContext = context;
              //     _telpoM8Plugin
              //         .generateQRCode('https://protechadvance.com')
              //         .then((Uint8List bytes) {
              //       final Image image = Image.memory(bytes);
              //       showDialog(
              //         context: currentContext,
              //         builder: (BuildContext dialogContext) {
              //           return AlertDialog(
              //             content: Container(
              //               child: image,
              //             ),
              //           );
              //         },
              //       );
              //     });
              //   },
              // ),
              // TextButton(
              //   child: const Text('Display Image on LCD'),
              //   onPressed: () async {
              //     // Replace 'https://example.com/my_image.jpg' with the actual URL of your image
              //     final response = await http.get(Uri.parse(
              //         'https://upload.wikimedia.org/wikipedia/commons/thumb/9/93/New-mtn-logo.jpg/800px-New-mtn-logo.jpg'));

              //     // Display the image in the app
              //     showDialog(
              //       context: context,           //       builder: (BuildContext context) {
              //         return AlertDialog(
              //           content: Image.memory(response.bodyBytes),
              //         );
              //       },
              //     );

              //     // Display the image on the LCD
              //     TelpoM8().displayImageOnLCD(response.bodyBytes);
              //   },
              // ),
              TextButton(
                child: const Text('Display Image on LCD...'),
                onPressed: () async {
                  // Replace 'https://example.com/my_image.jpg' with the actual URL of your image
                  final response = await http.get(Uri.parse(
                      'https://learnafricaplc.com/wp-content/uploads/2024/03/logo.jpg'));

                  // Convert the image to a byte array
                  final Uint8List imageBytes = response.bodyBytes;

                  // Display the image on the LCD
                  TelpoM8().displayImageOnLCD(imageBytes);
                },
              ),
              // TextButton(
              //   child: const Text('Display Image from Assets on LCD...'),
              //   onPressed: () async {
              //     // Load the image from the assets
              //     final ByteData bytes =
              //         await rootBundle.load('assets/images/icon.jpg');

              //     // Convert the ByteData to a Uint8List
              //     final Uint8List imageBytes = bytes.buffer.asUint8List();

              //     // Display the image on the LCD
              //     TelpoM8().displayImageOnLCD(imageBytes);
              //   },
              // ),

              TextButton(
                child: const Text('Print Text with Thermal Printer...'),
                onPressed: () async {
                  // Replace with the actual text you want to print
                  TelpoM8().printWithThermalPrinter('Line 1\nLine 2\nLine 3', 7);
                },
              ),
              TextButton(
                child: const Text('Print Receipt with Thermal Printer...'),
                onPressed: () async {
                  // Replace with the actual text you want to print
                  String receiptText = 'LOGO and paystrait\n'
                      'Name of Vendor\n' // This will be bold and large
                      'Amount: \n' // This will be bold and large
                      'Transaction status: \n' // This will be bold and large
                      'Transaction Id: \n'
                      'Date/Time of transaction: \n'
                      'In case of reprint, it should be stated as Reprint in the header';

                  TelpoM8().printWithThermalPrinter(receiptText, 7);
                },
              ),
              TextButton(
                child: const Text('Print QR Code with Thermal Printer...'),
                onPressed: () async {
                  // Replace with the actual text you want to print
                  String qrCodeText = 'LOGO and Paystrait\n'
                      'Name of the account holder\n'
                      'QR code\n'
                      'Expiration of the code';

                  TelpoM8().printWithThermalPrinter(qrCodeText, 7);
                },
              ),
              TextButton(
                child: const Text('Print Image with Thermal Printer...'),
                onPressed: () async {
                  // Replace 'https://example.com/my_image.jpg' with the actual URL of your image
                  final response = await http.get(Uri.parse(
                      'https://api.learnafrica.ng/storage/images/y0q3Euv8nv5iCY5ODrrZP1aOqtBsdg0oe0NVTqpw.png'));

                  // Convert the image to a byte array
                  final Uint8List imageBytes = response.bodyBytes;

                  // Print the image with the thermal printer
                  TelpoM8().printImageWithThermalPrinter(imageBytes, 7);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
150
points
21
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for interacting with Telpo M8 devices, allowing for operations such as displaying images on LCD, generating QR codes, and printing with a thermal printer.

Homepage
Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, image, plugin_platform_interface

More

Packages that depend on telpo_m8

Packages that implement telpo_m8