Files
tuiche/lib/pages/mh_page/device/model/BlueToothDataModel.dart
2025-07-01 21:01:28 +08:00

43 lines
1.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
class BlueToothDataModel {
String name; // 设备型号
bool bind;
String mac;
ScanResult scanResult;
String macA;
String macB;
int type;
String? macAID;
String? macBID;
DateTime lastSeen; // 添加的最后可见时间字段
BlueToothDataModel({
this.name = '',
required this.bind,
required this.mac,
required this.scanResult,
required this.type,
this.macA = '',
this.macB = '',
required this.lastSeen, // 添加到构造函数参数
});
factory BlueToothDataModel.fromScanResult(ScanResult result, int type,
{bool bind = false, String name = '', String mac = ''}) {
// 如果外部没有传入 name则取 localName
String finalName =
name.isNotEmpty ? name : (result.advertisementData.localName ?? '');
return BlueToothDataModel(
name: finalName,
bind: bind,
mac: mac,
scanResult: result,
type: type,
macA: '', // 保持原有默认值
macB: '', // 保持原有默认值
lastSeen: DateTime.now(), // 设置为当前时间
);
}
}