56 lines
1.2 KiB
Dart
56 lines
1.2 KiB
Dart
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; // 最后可见时间
|
|
String? deviceID; // 设备ID
|
|
int? version; // ✅ 新增版本号,可为空
|
|
|
|
BlueToothDataModel({
|
|
this.name = '',
|
|
required this.bind,
|
|
required this.mac,
|
|
required this.scanResult,
|
|
required this.type,
|
|
this.macA = '',
|
|
this.macB = '',
|
|
required this.lastSeen,
|
|
this.deviceID,
|
|
this.version, // ✅ 构造函数参数
|
|
});
|
|
|
|
factory BlueToothDataModel.fromScanResult(
|
|
ScanResult result,
|
|
int type, {
|
|
bool bind = false,
|
|
String name = '',
|
|
String mac = '',
|
|
String? deviceID,
|
|
int? version, // ✅ 工厂方法参数
|
|
}) {
|
|
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(),
|
|
deviceID: deviceID,
|
|
version: version, // ✅ 赋值
|
|
);
|
|
}
|
|
}
|