imin_printer 0.4.0 imin_printer: ^0.4.0 copied to clipboard
A Flutter plugin for using imin printer sdk in Android
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:imin_printer/imin_printer.dart';
import 'package:imin_printer/enums.dart';
import 'package:imin_printer/imin_style.dart';
import 'package:fluttertoast/fluttertoast.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final iminPrinter = IminPrinter();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Imin Printer Example'),
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
child: const Text('init Printer'),
onPressed: () async {
await iminPrinter.initPrinter();
}),
ElevatedButton(
onPressed: () async {
String? state = await iminPrinter.getPrinterStatus();
Fluttertoast.showToast(
msg: state ?? '',
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM, // 消息框弹出的位置
// timeInSecForIos: 1, // 消息框持续的时间(目前的版本只有ios有效)
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
},
child: const Text('getPrinterStatus')),
]),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
await iminPrinter.printText(
'iMin advocates the core values of "Integrity, Customer First, Invention&Creation, Patience”, using cloud-based technology to help businesses to get access to the Internet and also increases their data base, by providing more solutions so that their business can take a step further. Through their efficiency enhancement, cost improvement, service innovation, and better services for consumers, these aspect will drives the entire industry development.',
style: IminTextStyle(wordWrap: true));
},
child: const Text('Text in word wrap')),
ElevatedButton(
onPressed: () async {
await iminPrinter.printText('居中',
style:
IminTextStyle(align: IminPrintAlign.center));
},
child: const Text('text alignment'))
]),
),
const Divider(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
await iminPrinter.printText('测试字体大小',
style: IminTextStyle(fontSize: 80));
},
child: const Text('Text fontSize')),
ElevatedButton(
onPressed: () async {
await iminPrinter.printText('测试打印字体',
style: IminTextStyle(
typeface: IminTypeface.typefaceMonospace));
},
child: const Text('Text typeface'))
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
await iminPrinter.printText('测试打印字体样式',
style: IminTextStyle(
fontStyle: IminFontStyle.boldItalic));
},
child: const Text('Text style')),
ElevatedButton(
onPressed: () async {
Uint8List byte = await _getImageFromAsset(
'assets/images/doraemon.jpg');
await iminPrinter.printSingleBitmap(byte);
},
child: const Text('print singleBitmap'))
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
await iminPrinter.printText(
'iMin is a service provider who focuses mainly on the field of business intelligence, bringing IoT, AI and cloud service to the business sector. We develop and provide a wide range of intelligent commercial hardware solutions which help businesses to run more cost effectively.');
},
child: const Text('print Text')),
ElevatedButton(
onPressed: () async {
Uint8List byte =
await readFileBytes('assets/images/logo.png');
await iminPrinter.printSingleBitmap(byte,
alignment: IminPrintAlign.right);
},
child: const Text('print singleBitmap in align'))
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () async {
await iminPrinter.printQrCode('https://www.imin.sg',
qrCodeStyle: IminQrCodeStyle(
errorCorrectionLevel:
IminQrcodeCorrectionLevel.levelH,
qrSize: 4,
align: IminPrintAlign.right));
},
child: const Text('print QrCode'))
],
),
)
],
)),
),
);
}
}
Future<Uint8List> readFileBytes(String path) async {
ByteData fileData = await rootBundle.load(path);
Uint8List fileUnit8List = fileData.buffer
.asUint8List(fileData.offsetInBytes, fileData.lengthInBytes);
return fileUnit8List;
}
Future<Uint8List> _getImageFromAsset(String iconPath) async {
return await readFileBytes(iconPath);
}