diff --git a/lib/models/file_pool.dart b/lib/models/file_pool.dart index 1f65c862..f84461f8 100644 --- a/lib/models/file_pool.dart +++ b/lib/models/file_pool.dart @@ -1,36 +1,37 @@ -class FilePool { - final String id; - final String name; - final String? description; - final Map storageConfig; - final Map billingConfig; - final Map policyConfig; - final bool isHidden; +import 'package:freezed_annotation/freezed_annotation.dart'; - FilePool({ - required this.id, - required this.name, - this.description, - required this.storageConfig, - required this.billingConfig, - required this.policyConfig, - required this.isHidden, - }); +part 'file_pool.freezed.dart'; +part 'file_pool.g.dart'; - factory FilePool.fromJson(Map json) { - return FilePool( - id: json['id'] as String, - name: json['name'] as String, - description: json['description'] as String?, - storageConfig: json['storage_config'] as Map, - billingConfig: json['billing_config'] as Map, - policyConfig: json['policy_config'] as Map, - isHidden: json['is_hidden'] as bool, - ); - } +@freezed +sealed class SnFilePool with _$SnFilePool { + const factory SnFilePool({ + required String id, + required String name, + String? description, + Map? storageConfig, + Map? billingConfig, + Map? policyConfig, + bool? isHidden, + String? accountId, + String? resourceIdentifier, + DateTime? createdAt, + DateTime? updatedAt, + DateTime? deletedAt, + }) = _SnFilePool; - static List listFromResponse(dynamic data) { - final parsed = data as List; - return parsed.map((e) => FilePool.fromJson(e)).toList(); + factory SnFilePool.fromJson(Map json) => + _$SnFilePoolFromJson(json); +} + +extension SnFilePoolList on SnFilePool { + static List listFromResponse(dynamic data) { + if (data is List) { + return data + .whereType>() + .map(SnFilePool.fromJson) + .toList(); + } + throw ArgumentError('Unexpected response format: $data'); } } diff --git a/lib/models/file_pool.freezed.dart b/lib/models/file_pool.freezed.dart new file mode 100644 index 00000000..e262caa5 --- /dev/null +++ b/lib/models/file_pool.freezed.dart @@ -0,0 +1,328 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'file_pool.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +// dart format off +T _$identity(T value) => value; + +/// @nodoc +mixin _$SnFilePool { + + String get id; String get name; String? get description; Map? get storageConfig; Map? get billingConfig; Map? get policyConfig; bool? get isHidden; String? get accountId; String? get resourceIdentifier; DateTime? get createdAt; DateTime? get updatedAt; DateTime? get deletedAt; +/// Create a copy of SnFilePool +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$SnFilePoolCopyWith get copyWith => _$SnFilePoolCopyWithImpl(this as SnFilePool, _$identity); + + /// Serializes this SnFilePool to a JSON map. + Map toJson(); + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is SnFilePool&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&const DeepCollectionEquality().equals(other.storageConfig, storageConfig)&&const DeepCollectionEquality().equals(other.billingConfig, billingConfig)&&const DeepCollectionEquality().equals(other.policyConfig, policyConfig)&&(identical(other.isHidden, isHidden) || other.isHidden == isHidden)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.resourceIdentifier, resourceIdentifier) || other.resourceIdentifier == resourceIdentifier)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)); +} + +@JsonKey(includeFromJson: false, includeToJson: false) +@override +int get hashCode => Object.hash(runtimeType,id,name,description,const DeepCollectionEquality().hash(storageConfig),const DeepCollectionEquality().hash(billingConfig),const DeepCollectionEquality().hash(policyConfig),isHidden,accountId,resourceIdentifier,createdAt,updatedAt,deletedAt); + +@override +String toString() { + return 'SnFilePool(id: $id, name: $name, description: $description, storageConfig: $storageConfig, billingConfig: $billingConfig, policyConfig: $policyConfig, isHidden: $isHidden, accountId: $accountId, resourceIdentifier: $resourceIdentifier, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)'; +} + + +} + +/// @nodoc +abstract mixin class $SnFilePoolCopyWith<$Res> { + factory $SnFilePoolCopyWith(SnFilePool value, $Res Function(SnFilePool) _then) = _$SnFilePoolCopyWithImpl; +@useResult +$Res call({ + String id, String name, String? description, Map? storageConfig, Map? billingConfig, Map? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt +}); + + + + +} +/// @nodoc +class _$SnFilePoolCopyWithImpl<$Res> + implements $SnFilePoolCopyWith<$Res> { + _$SnFilePoolCopyWithImpl(this._self, this._then); + + final SnFilePool _self; + final $Res Function(SnFilePool) _then; + +/// Create a copy of SnFilePool +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? description = freezed,Object? storageConfig = freezed,Object? billingConfig = freezed,Object? policyConfig = freezed,Object? isHidden = freezed,Object? accountId = freezed,Object? resourceIdentifier = freezed,Object? createdAt = freezed,Object? updatedAt = freezed,Object? deletedAt = freezed,}) { + return _then(_self.copyWith( +id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable +as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable +as String?,storageConfig: freezed == storageConfig ? _self.storageConfig : storageConfig // ignore: cast_nullable_to_non_nullable +as Map?,billingConfig: freezed == billingConfig ? _self.billingConfig : billingConfig // ignore: cast_nullable_to_non_nullable +as Map?,policyConfig: freezed == policyConfig ? _self.policyConfig : policyConfig // ignore: cast_nullable_to_non_nullable +as Map?,isHidden: freezed == isHidden ? _self.isHidden : isHidden // ignore: cast_nullable_to_non_nullable +as bool?,accountId: freezed == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable +as String?,resourceIdentifier: freezed == resourceIdentifier ? _self.resourceIdentifier : resourceIdentifier // ignore: cast_nullable_to_non_nullable +as String?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable +as DateTime?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable +as DateTime?,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable +as DateTime?, + )); +} + +} + + +/// Adds pattern-matching-related methods to [SnFilePool]. +extension SnFilePoolPatterns on SnFilePool { +/// A variant of `map` that fallback to returning `orElse`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeMap(TResult Function( _SnFilePool value)? $default,{required TResult orElse(),}){ +final _that = this; +switch (_that) { +case _SnFilePool() when $default != null: +return $default(_that);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// Callbacks receives the raw object, upcasted. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case final Subclass2 value: +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult map(TResult Function( _SnFilePool value) $default,){ +final _that = this; +switch (_that) { +case _SnFilePool(): +return $default(_that);} +} +/// A variant of `map` that fallback to returning `null`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? mapOrNull(TResult? Function( _SnFilePool value)? $default,){ +final _that = this; +switch (_that) { +case _SnFilePool() when $default != null: +return $default(_that);case _: + return null; + +} +} +/// A variant of `when` that fallback to an `orElse` callback. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String name, String? description, Map? storageConfig, Map? billingConfig, Map? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt)? $default,{required TResult orElse(),}) {final _that = this; +switch (_that) { +case _SnFilePool() when $default != null: +return $default(_that.id,_that.name,_that.description,_that.storageConfig,_that.billingConfig,_that.policyConfig,_that.isHidden,_that.accountId,_that.resourceIdentifier,_that.createdAt,_that.updatedAt,_that.deletedAt);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// As opposed to `map`, this offers destructuring. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case Subclass2(:final field2): +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult when(TResult Function( String id, String name, String? description, Map? storageConfig, Map? billingConfig, Map? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt) $default,) {final _that = this; +switch (_that) { +case _SnFilePool(): +return $default(_that.id,_that.name,_that.description,_that.storageConfig,_that.billingConfig,_that.policyConfig,_that.isHidden,_that.accountId,_that.resourceIdentifier,_that.createdAt,_that.updatedAt,_that.deletedAt);} +} +/// A variant of `when` that fallback to returning `null` +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String name, String? description, Map? storageConfig, Map? billingConfig, Map? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt)? $default,) {final _that = this; +switch (_that) { +case _SnFilePool() when $default != null: +return $default(_that.id,_that.name,_that.description,_that.storageConfig,_that.billingConfig,_that.policyConfig,_that.isHidden,_that.accountId,_that.resourceIdentifier,_that.createdAt,_that.updatedAt,_that.deletedAt);case _: + return null; + +} +} + +} + +/// @nodoc +@JsonSerializable() + +class _SnFilePool implements SnFilePool { + const _SnFilePool({required this.id, required this.name, this.description, final Map? storageConfig, final Map? billingConfig, final Map? policyConfig, this.isHidden, this.accountId, this.resourceIdentifier, this.createdAt, this.updatedAt, this.deletedAt}): _storageConfig = storageConfig,_billingConfig = billingConfig,_policyConfig = policyConfig; + factory _SnFilePool.fromJson(Map json) => _$SnFilePoolFromJson(json); + +@override final String id; +@override final String name; +@override final String? description; + final Map? _storageConfig; +@override Map? get storageConfig { + final value = _storageConfig; + if (value == null) return null; + if (_storageConfig is EqualUnmodifiableMapView) return _storageConfig; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); +} + + final Map? _billingConfig; +@override Map? get billingConfig { + final value = _billingConfig; + if (value == null) return null; + if (_billingConfig is EqualUnmodifiableMapView) return _billingConfig; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); +} + + final Map? _policyConfig; +@override Map? get policyConfig { + final value = _policyConfig; + if (value == null) return null; + if (_policyConfig is EqualUnmodifiableMapView) return _policyConfig; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); +} + +@override final bool? isHidden; +@override final String? accountId; +@override final String? resourceIdentifier; +@override final DateTime? createdAt; +@override final DateTime? updatedAt; +@override final DateTime? deletedAt; + +/// Create a copy of SnFilePool +/// with the given fields replaced by the non-null parameter values. +@override @JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +_$SnFilePoolCopyWith<_SnFilePool> get copyWith => __$SnFilePoolCopyWithImpl<_SnFilePool>(this, _$identity); + +@override +Map toJson() { + return _$SnFilePoolToJson(this, ); +} + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnFilePool&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&const DeepCollectionEquality().equals(other._storageConfig, _storageConfig)&&const DeepCollectionEquality().equals(other._billingConfig, _billingConfig)&&const DeepCollectionEquality().equals(other._policyConfig, _policyConfig)&&(identical(other.isHidden, isHidden) || other.isHidden == isHidden)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.resourceIdentifier, resourceIdentifier) || other.resourceIdentifier == resourceIdentifier)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt)); +} + +@JsonKey(includeFromJson: false, includeToJson: false) +@override +int get hashCode => Object.hash(runtimeType,id,name,description,const DeepCollectionEquality().hash(_storageConfig),const DeepCollectionEquality().hash(_billingConfig),const DeepCollectionEquality().hash(_policyConfig),isHidden,accountId,resourceIdentifier,createdAt,updatedAt,deletedAt); + +@override +String toString() { + return 'SnFilePool(id: $id, name: $name, description: $description, storageConfig: $storageConfig, billingConfig: $billingConfig, policyConfig: $policyConfig, isHidden: $isHidden, accountId: $accountId, resourceIdentifier: $resourceIdentifier, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)'; +} + + +} + +/// @nodoc +abstract mixin class _$SnFilePoolCopyWith<$Res> implements $SnFilePoolCopyWith<$Res> { + factory _$SnFilePoolCopyWith(_SnFilePool value, $Res Function(_SnFilePool) _then) = __$SnFilePoolCopyWithImpl; +@override @useResult +$Res call({ + String id, String name, String? description, Map? storageConfig, Map? billingConfig, Map? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt +}); + + + + +} +/// @nodoc +class __$SnFilePoolCopyWithImpl<$Res> + implements _$SnFilePoolCopyWith<$Res> { + __$SnFilePoolCopyWithImpl(this._self, this._then); + + final _SnFilePool _self; + final $Res Function(_SnFilePool) _then; + +/// Create a copy of SnFilePool +/// with the given fields replaced by the non-null parameter values. +@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? description = freezed,Object? storageConfig = freezed,Object? billingConfig = freezed,Object? policyConfig = freezed,Object? isHidden = freezed,Object? accountId = freezed,Object? resourceIdentifier = freezed,Object? createdAt = freezed,Object? updatedAt = freezed,Object? deletedAt = freezed,}) { + return _then(_SnFilePool( +id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable +as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable +as String?,storageConfig: freezed == storageConfig ? _self._storageConfig : storageConfig // ignore: cast_nullable_to_non_nullable +as Map?,billingConfig: freezed == billingConfig ? _self._billingConfig : billingConfig // ignore: cast_nullable_to_non_nullable +as Map?,policyConfig: freezed == policyConfig ? _self._policyConfig : policyConfig // ignore: cast_nullable_to_non_nullable +as Map?,isHidden: freezed == isHidden ? _self.isHidden : isHidden // ignore: cast_nullable_to_non_nullable +as bool?,accountId: freezed == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable +as String?,resourceIdentifier: freezed == resourceIdentifier ? _self.resourceIdentifier : resourceIdentifier // ignore: cast_nullable_to_non_nullable +as String?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable +as DateTime?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable +as DateTime?,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable +as DateTime?, + )); +} + + +} + +// dart format on diff --git a/lib/models/file_pool.g.dart b/lib/models/file_pool.g.dart new file mode 100644 index 00000000..a2b2cb4d --- /dev/null +++ b/lib/models/file_pool.g.dart @@ -0,0 +1,47 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'file_pool.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_SnFilePool _$SnFilePoolFromJson(Map json) => _SnFilePool( + id: json['id'] as String, + name: json['name'] as String, + description: json['description'] as String?, + storageConfig: json['storage_config'] as Map?, + billingConfig: json['billing_config'] as Map?, + policyConfig: json['policy_config'] as Map?, + isHidden: json['is_hidden'] as bool?, + accountId: json['account_id'] as String?, + resourceIdentifier: json['resource_identifier'] as String?, + createdAt: + json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String), + updatedAt: + json['updated_at'] == null + ? null + : DateTime.parse(json['updated_at'] as String), + deletedAt: + json['deleted_at'] == null + ? null + : DateTime.parse(json['deleted_at'] as String), +); + +Map _$SnFilePoolToJson(_SnFilePool instance) => + { + 'id': instance.id, + 'name': instance.name, + 'description': instance.description, + 'storage_config': instance.storageConfig, + 'billing_config': instance.billingConfig, + 'policy_config': instance.policyConfig, + 'is_hidden': instance.isHidden, + 'account_id': instance.accountId, + 'resource_identifier': instance.resourceIdentifier, + 'created_at': instance.createdAt?.toIso8601String(), + 'updated_at': instance.updatedAt?.toIso8601String(), + 'deleted_at': instance.deletedAt?.toIso8601String(), + }; diff --git a/lib/pods/pool_provider.dart b/lib/pods/pool_provider.dart index 95ce2dc6..b267fed8 100644 --- a/lib/pods/pool_provider.dart +++ b/lib/pods/pool_provider.dart @@ -1,6 +1,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../services/pool_service.dart'; -import '../models/file_pool.dart'; +import 'package:island/services/pool_service.dart'; +import 'package:island/models/file_pool.dart'; import 'package:island/pods/network.dart'; final poolServiceProvider = Provider((ref) { @@ -8,7 +8,7 @@ final poolServiceProvider = Provider((ref) { return PoolService(dio); }); -final poolsProvider = FutureProvider>((ref) async { +final poolsProvider = FutureProvider>((ref) async { final service = ref.watch(poolServiceProvider); return service.fetchPools(); }); diff --git a/lib/screens/account/profile.g.dart b/lib/screens/account/profile.g.dart index b977e0f7..318d54da 100644 --- a/lib/screens/account/profile.g.dart +++ b/lib/screens/account/profile.g.dart @@ -268,7 +268,7 @@ class _AccountBadgesProviderElement } String _$accountAppbarForcegroundColorHash() => - r'8ee0cae10817b77fb09548a482f5247662b4374c'; + r'127fcc7fd6ec6a41ac4a6975276b5271aa4fa7d0'; /// See also [accountAppbarForcegroundColor]. @ProviderFor(accountAppbarForcegroundColor) diff --git a/lib/screens/auth/captcha.config.g.dart b/lib/screens/auth/captcha.config.g.dart index 24ce9089..578422f0 100644 --- a/lib/screens/auth/captcha.config.g.dart +++ b/lib/screens/auth/captcha.config.g.dart @@ -6,7 +6,7 @@ part of 'captcha.config.dart'; // RiverpodGenerator // ************************************************************************** -String _$captchaUrlHash() => r'bbed0d18272dd205069642b3c6583ea2eef735d1'; +String _$captchaUrlHash() => r'd46bc43032cef504547cd528a40c23cf76f27cc8'; /// See also [captchaUrl]. @ProviderFor(captchaUrl) diff --git a/lib/screens/posts/pub_profile.g.dart b/lib/screens/posts/pub_profile.g.dart index 03919de3..3f3ed561 100644 --- a/lib/screens/posts/pub_profile.g.dart +++ b/lib/screens/posts/pub_profile.g.dart @@ -400,7 +400,7 @@ class _PublisherSubscriptionStatusProviderElement } String _$publisherAppbarForcegroundColorHash() => - r'd781a806a242aea5c1609ec98c97c52fdd9f7db1'; + r'cd9a9816177a6eecc2bc354acebbbd48892ffdd7'; /// See also [publisherAppbarForcegroundColor]. @ProviderFor(publisherAppbarForcegroundColor) diff --git a/lib/screens/realm/realm_detail.g.dart b/lib/screens/realm/realm_detail.g.dart index c369db6c..75494f99 100644 --- a/lib/screens/realm/realm_detail.g.dart +++ b/lib/screens/realm/realm_detail.g.dart @@ -7,7 +7,7 @@ part of 'realm_detail.dart'; // ************************************************************************** String _$realmAppbarForegroundColorHash() => - r'14b5563d861996ea182d0d2db7aa5c2bb3bbaf48'; + r'8131c047a984318a4cc3fbb5daa5ef0ce44dfae5'; /// Copied from Dart SDK class _SystemHash { diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index c3a591ec..cd28b948 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -373,7 +373,7 @@ class SettingsScreen extends HookConsumerWidget { poolsAsync.when( data: (pools) { final validPools = filterValidPools(pools); - final currentPoolId = resolveDefaultPoolId(ref, pools); + final currentPoolId = resolveDefaultPoolId(ref, validPools); return ListTile( isThreeLine: true, @@ -392,12 +392,14 @@ class SettingsScreen extends HookConsumerWidget { child: DropdownButton2( isExpanded: true, items: - validPools.map((p) { - return DropdownMenuItem( - value: p.id, - child: Text(p.name).fontSize(14), - ); - }).toList(), + validPools + .map( + (p) => DropdownMenuItem( + value: p.id, + child: Text(p.name).fontSize(14), + ), + ) + .toList(), value: currentPoolId, onChanged: (value) { ref diff --git a/lib/services/pool_service.dart b/lib/services/pool_service.dart index bbd120a2..8cef98e6 100644 --- a/lib/services/pool_service.dart +++ b/lib/services/pool_service.dart @@ -7,11 +7,11 @@ class PoolService { PoolService(this._dio); - Future> fetchPools() async { + Future> fetchPools() async { final response = await _dio.get('/drive/pools'); if (response.statusCode == 200) { - return FilePool.listFromResponse(response.data); + return SnFilePoolList.listFromResponse(response.data); } else { throw Exception('Failed to fetch pools: ${response.statusCode}'); } diff --git a/lib/utils/pool_utils.dart b/lib/utils/pool_utils.dart index 12d34d54..e3476a90 100644 --- a/lib/utils/pool_utils.dart +++ b/lib/utils/pool_utils.dart @@ -1,35 +1,37 @@ - -import '../models/file_pool.dart'; +import 'package:island/models/file_pool.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../pods/config.dart'; +import 'package:island/pods/config.dart'; -List filterValidPools(List pools) { +List filterValidPools(List pools) { return pools.where((p) { - final accept = p.policyConfig['accept_types']; - if (accept != null) { + final accept = p.policyConfig?['accept_types']; + + if (accept is List) { final acceptsOnlyMedia = accept.every((t) => - t.startsWith('image/') || - t.startsWith('video/') || - t.startsWith('audio/')); + t is String && + (t.startsWith('image/') || + t.startsWith('video/') || + t.startsWith('audio/'))); if (acceptsOnlyMedia) return false; } + return true; }).toList(); } -String resolveDefaultPoolId(WidgetRef ref, List pools) { +String resolveDefaultPoolId(WidgetRef ref, List pools) { final settings = ref.watch(appSettingsNotifierProvider); final validPools = filterValidPools(pools); - if (settings.defaultPoolId != null && - validPools.any((p) => p.id == settings.defaultPoolId)) { - return settings.defaultPoolId!; + final configuredId = settings.defaultPoolId; + if (configuredId != null && + validPools.any((p) => p.id == configuredId)) { + return configuredId; } if (validPools.isNotEmpty) { return validPools.first.id; } - // DEFAULT: Solar Network Driver - return '500e5ed8-bd44-4359-bc0a-ec85e2adf447'; -} + return '500e5ed8-bd44-4359-bc0a-ec85e2adf447'; // Solar Network Driver +}