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.

52 lines
1.2 KiB

3 years ago
import 'package:flutter/material.dart';
import 'package:hy_printer/device.dart';
import 'package:hy_printer/hy_printer.dart';
class ScanPage extends StatefulWidget {
const ScanPage({Key? key}) : super(key: key);
@override
_ScanPageState createState() => _ScanPageState();
}
class _ScanPageState extends State<ScanPage> {
List<Device> _devices = [];
@override
void initState() {
init();
super.initState();
}
Future init() async {
_devices = await HyPrinter.getDeiveces();
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('设备列表'),
),
body: ListView(
padding: const EdgeInsets.all(10),
children: _devices
.map((e) => TextButton(
onPressed: () async {
var result = await HyPrinter.connect(e.address);
if (result == 0) {
Navigator.pop(context);
}
},
child: Column(
children: [
Text(e.name),
Text(e.address),
],
)))
.toList()),
);
}
}