|
|
|
@ -118,57 +118,51 @@ class DevicesView extends GetView<DevicesController> { |
|
|
|
} |
|
|
|
|
|
|
|
Widget _buildDevicesList(bool isDarkMode) { |
|
|
|
final devices = User.instance.devices; |
|
|
|
return Obx(() { |
|
|
|
// 使用控制器的响应式数据,这会触发控制器的实例化 |
|
|
|
final groupedDevices = controller.devices; |
|
|
|
|
|
|
|
if (devices.isEmpty) { |
|
|
|
return _buildEmptyState(isDarkMode); |
|
|
|
} |
|
|
|
|
|
|
|
// 按设备类型分组 |
|
|
|
final Map<DeviceType, List<UserDevice>> groupedDevices = {}; |
|
|
|
for (var device in devices) { |
|
|
|
final deviceType = DeviceType.fromValue(device.devicetype); |
|
|
|
if (!groupedDevices.containsKey(deviceType)) { |
|
|
|
groupedDevices[deviceType] = []; |
|
|
|
if (groupedDevices.isEmpty) { |
|
|
|
return _buildEmptyState(isDarkMode); |
|
|
|
} |
|
|
|
groupedDevices[deviceType]!.add(device); |
|
|
|
} |
|
|
|
|
|
|
|
return ListView( |
|
|
|
padding: EdgeInsets.all(20.w), |
|
|
|
children: [ |
|
|
|
// 遍历每个设备类型 |
|
|
|
...groupedDevices.entries.map((entry) { |
|
|
|
final deviceType = entry.key; |
|
|
|
final deviceList = entry.value; |
|
|
|
return ListView( |
|
|
|
padding: EdgeInsets.all(20.w), |
|
|
|
children: [ |
|
|
|
// 遍历每个设备类型 |
|
|
|
...groupedDevices.entries.map((entry) { |
|
|
|
final deviceTypeValue = entry.key; |
|
|
|
final deviceList = entry.value; |
|
|
|
final deviceType = DeviceType.fromValue(deviceTypeValue); |
|
|
|
|
|
|
|
return Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
// 设备类型标题 |
|
|
|
Padding( |
|
|
|
padding: EdgeInsets.only(bottom: 12.h), |
|
|
|
child: Text( |
|
|
|
deviceType.displayName, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
fontWeight: FontWeight.w600, |
|
|
|
color: isDarkMode ? Colors.white : Colors.black87, |
|
|
|
return Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
// 设备类型标题 |
|
|
|
Padding( |
|
|
|
padding: EdgeInsets.only(bottom: 12.h), |
|
|
|
child: Text( |
|
|
|
deviceType.displayName, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
fontWeight: FontWeight.w600, |
|
|
|
color: isDarkMode ? Colors.white : Colors.black87, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
// 该类型下的设备列表 |
|
|
|
...deviceList.map((device) => _buildDeviceCard( |
|
|
|
device: device, |
|
|
|
deviceType: deviceType, |
|
|
|
isDarkMode: isDarkMode, |
|
|
|
)), |
|
|
|
SizedBox(height: 20.h), |
|
|
|
], |
|
|
|
); |
|
|
|
}).toList(), |
|
|
|
], |
|
|
|
); |
|
|
|
// 该类型下的设备列表 |
|
|
|
...deviceList.map((device) => _buildDeviceCard( |
|
|
|
device: device, |
|
|
|
deviceType: deviceType, |
|
|
|
isDarkMode: isDarkMode, |
|
|
|
)), |
|
|
|
SizedBox(height: 20.h), |
|
|
|
], |
|
|
|
); |
|
|
|
}).toList(), |
|
|
|
], |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _buildEmptyState(bool isDarkMode) { |
|
|
|
|