Skip to content

Commit

Permalink
🔧 Fix: Try to fix dumplicate key error with ValueKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynesshely committed Apr 2, 2024
1 parent 58c7169 commit ad26d7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 12 additions & 7 deletions kitx_mobile/lib/pages/devices_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:kitx_mobile/pages/controls/device_status_icon.dart';
import 'package:kitx_mobile/pages/controls/device_status_label.dart';
import 'package:kitx_mobile/pages/pages.dart';
import 'package:kitx_mobile/pages/sub_pages/device_chat_page.dart';
import 'package:kitx_mobile/utils/extensions/device_info_ext.dart';
import 'package:kitx_mobile/utils/handlers/vibration_handler.dart';
import 'package:kitx_shared_dart/kitx_shared_dart.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';
Expand Down Expand Up @@ -140,17 +141,24 @@ class _DevicesPage extends State<DevicesPage> {
physics: NeverScrollableScrollPhysics(),
itemCount: instances.devicesService.length + 1,
itemBuilder: (_, index) {
if (index >= instances.devicesService.length) {
return const SizedBox(
key: ValueKey('PlacerEmptySizedBox'),
height: 300,
);
}

var list = instances.devicesService.deviceInfoList;
var info = index >= instances.devicesService.length ? null : list[index];
var info = list[index];
return DeviceCard(
info,
index,
key: Key('${info?.device.deviceName ?? ''}${info?.device.iPv4 ?? ''}'),
key: info.getValueKey(),
shouldDelay: justEnteredPage,
shouldScaleIn: instances.appInfo.animationEnabled.value,
onTap: () {
VibrationHandler.tryVibrate();
if (info != null) selectedDeviceInfo.value = info;
selectedDeviceInfo.value = info;
_paneController.open();
},
);
Expand All @@ -174,10 +182,7 @@ class _DevicesPage extends State<DevicesPage> {
instances.devicesService.deviceInfoList[i],
i,
width: (MediaQuery.of(context).size.width - 20) * deviceCardHorizontalScale,
key: Key(
'${instances.devicesService.deviceInfoList[i].device.deviceName}'
'${instances.devicesService.deviceInfoList[i].device.iPv4}',
),
key: instances.devicesService.deviceInfoList[i].getValueKey(),
shouldDelay: justEnteredPage,
shouldScaleIn: instances.appInfo.animationEnabled.value,
onTap: () {
Expand Down
10 changes: 10 additions & 0 deletions kitx_mobile/lib/utils/extensions/device_info_ext.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/foundation.dart';
import 'package:kitx_shared_dart/kitx_shared_dart.dart';

/// Device Info Extensions
extension DeviceInfoExtensions on DeviceInfo {
/// Get Value Key
ValueKey getValueKey() {
return ValueKey('${device.deviceName} (${device.macAddress})');
}
}

0 comments on commit ad26d7b

Please sign in to comment.