gv_print_plugin 0.0.2
gv_print_plugin: ^0.0.2 copied to clipboard
金益M700打印机插件
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gv_print_plugin/gv_print_plugin.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 _gvPrintPlugin = GvPrintPlugin();
// 基本方法:直接从 assets 加载为 Uint8List
static Future<Uint8List> loadImageBytes(String assetPath) async {
try {
final ByteData data = await rootBundle.load(assetPath);
return data.buffer.asUint8List();
} catch (e) {
print('Error loading image from assets: $e');
throw e;
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('金益M700打印插件')),
body: Center(
child: Column(
children: [
SizedBox(height: 30),
OutlinedButton(
onPressed: () async {
final Uint8List imageBytes = await loadImageBytes(
"assets/sunmi.jpg",
);
var res = await _gvPrintPlugin.printImage(imageBytes);
print(res);
},
child: Text("打印图片"),
),
SizedBox(height: 30),
OutlinedButton(
onPressed: () async {
PrintParams params = PrintParams(
roadNetwork: '路网',
stationCode: '站码',
stationName: '收费站名称',
vehicleModel: '车型',
licensePlate: '车牌号码',
plateColor: '车牌颜色',
createDate: '2025-09-30 00:25:51',
couponNumber: '10000000000001',
qrcode: '二维码内容',
);
var res = await _gvPrintPlugin.printData(params);
print(res);
},
child: Text("打印通行纸券"),
),
],
),
),
),
);
}
}