You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.9 KiB

3 years ago
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:hy_printer/hy_printer.dart';
import 'package:hy_printer_example/scan_page.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
if (!mounted) return;
setState(() {});
}
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Home(),
);
}
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
int status = -1;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
TextButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) {
return const ScanPage();
}));
},
child: const Text('扫描设备')),
TextButton(
onPressed: () async {
await HyPrinter.disConnect();
},
child: const Text('断开连接')),
TextButton(
onPressed: () async {
status = await HyPrinter.getStatus();
setState(() {});
},
child: Text('$status')),
TextButton(
onPressed: () async {
await HyPrinter.printAsOrder(
code: 'ASASNB2021121200011',
3 years ago
fbaCode: '',
channel: "",
country: '',
count: "2/10",
hasPlan: false);
3 years ago
setState(() {});
},
3 years ago
child: const Text('打印面单')),
TextButton(
onPressed: () async {
3 years ago
await HyPrinter.printAsOrder(
code: 'ASASNB2021121200010002',
fbaCode: 'FBA15RY33MN8U00001',
channel: "欧洲特快",
country: '法国',
count: "2/10",
hasPlan: true);
setState(() {});
},
child: const Text('打印FBA面单')),
3 years ago
TextButton(
onPressed: () async {
await HyPrinter.printBarCode(0, 0, "2", "1", "130", "45", "26",
true, "8", "14", "12345678");
setState(() {});
},
child: const Text('打印条码')),
],
)),
);
}
}