fix: Make dropletIds field for DigitalOceanVolume optional

This commit is contained in:
NaiJi 2023-06-13 23:36:02 -03:00
parent f6424200e2
commit 65283306a9
3 changed files with 5 additions and 3 deletions

View file

@ -15,7 +15,7 @@ class DigitalOceanVolume {
final String name;
@JsonKey(name: 'droplet_ids')
final List<int> dropletIds;
final List<int>? dropletIds;
@JsonKey(name: 'size_gigabytes')
final int sizeGigabytes;

View file

@ -11,7 +11,7 @@ DigitalOceanVolume _$DigitalOceanVolumeFromJson(Map<String, dynamic> json) =>
json['id'] as String,
json['name'] as String,
json['size_gigabytes'] as int,
(json['droplet_ids'] as List<dynamic>).map((e) => e as int).toList(),
(json['droplet_ids'] as List<dynamic>?)?.map((e) => e as int).toList(),
);
Map<String, dynamic> _$DigitalOceanVolumeToJson(DigitalOceanVolume instance) =>

View file

@ -647,7 +647,9 @@ class DigitalOceanServerProvider extends ServerProvider {
name: volumeName,
sizeByte: rawVolume.sizeGigabytes * 1024 * 1024 * 1024,
serverId:
rawVolume.dropletIds.isNotEmpty ? rawVolume.dropletIds[0] : null,
(rawVolume.dropletIds != null && rawVolume.dropletIds!.isNotEmpty)
? rawVolume.dropletIds![0]
: null,
linuxDevice: 'scsi-0DO_Volume_$volumeName',
uuid: rawVolume.id,
);