telpo_m8 0.0.6
telpo_m8: ^0.0.6 copied to clipboard
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 'Hello, world!' with the actual text you want to print
TelpoM8().printWithThermalPrinter('=== Hello, world! ====');
},
),
],
),
),
),
);
}
}