81 lines
2.2 KiB
Dart
81 lines
2.2 KiB
Dart
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:vbvs_app/common/util/FirmwareVersionService.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; // ✅ 新增版本号,可为空
|
|
int? rssi; //信号强度
|
|
bool? selected; //是否选中
|
|
int? process = 0; //升级进度
|
|
int? newVersion; //升级版本
|
|
FirmwareVersionInfo? upgradeInfo;//升级固件信息
|
|
int? upgradeStatus;//升级状态
|
|
|
|
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, // ✅ 构造函数参数
|
|
this.rssi, // ✅ 构造函数参数
|
|
this.selected, // ✅ 构造函数参数
|
|
this.process, // ✅ 构造函数参数
|
|
this.newVersion, // ✅ 构造函数参数
|
|
this.upgradeInfo, // ✅ 构造函数参数
|
|
this.upgradeStatus, // ✅ 构造函数参数
|
|
});
|
|
|
|
factory BlueToothDataModel.fromScanResult(
|
|
ScanResult result,
|
|
int type, {
|
|
bool bind = false,
|
|
String name = '',
|
|
String mac = '',
|
|
String? deviceID,
|
|
int? version, // ✅ 工厂方法参数
|
|
int? rssi, // ✅ 工厂方法参数
|
|
bool? selected, // ✅ 工厂方法参数
|
|
int? process, // ✅ 工厂方法参数
|
|
int? newVersion, // ✅ 工厂方法参数
|
|
FirmwareVersionInfo? upgradeInfo, // ✅ 工厂方法参数
|
|
int? upgradeStatus, // ✅ 工厂方法参数
|
|
}) {
|
|
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, // ✅ 赋值
|
|
rssi: rssi,
|
|
selected: selected,
|
|
process: process,
|
|
newVersion: newVersion,
|
|
upgradeInfo: upgradeInfo,
|
|
upgradeStatus: upgradeStatus,
|
|
);
|
|
}
|
|
}
|