mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-18 14:49:15 +00:00
45 lines
1.1 KiB
Dart
45 lines
1.1 KiB
Dart
part of 'providers_cubit.dart';
|
|
|
|
class ProvidersState extends Equatable {
|
|
const ProvidersState(this.all);
|
|
|
|
final List<ProviderModel> all;
|
|
|
|
ProvidersState updateElement(
|
|
final ProviderModel provider,
|
|
final StateType newState,
|
|
) {
|
|
final List<ProviderModel> newList = [...all];
|
|
final int index = newList.indexOf(provider);
|
|
newList[index] = provider.updateState(newState);
|
|
return ProvidersState(newList);
|
|
}
|
|
|
|
List<ProviderModel> get connected => all
|
|
.where((final service) => service.state != StateType.uninitialized)
|
|
.toList();
|
|
|
|
List<ProviderModel> get uninitialized => all
|
|
.where((final service) => service.state == StateType.uninitialized)
|
|
.toList();
|
|
|
|
bool get isFullyInitialized => uninitialized.isEmpty;
|
|
|
|
@override
|
|
List<Object> get props => all;
|
|
}
|
|
|
|
class InitialProviderState extends ProvidersState {
|
|
InitialProviderState()
|
|
: super(
|
|
ProviderType.values
|
|
.map(
|
|
(final type) => ProviderModel(
|
|
state: StateType.uninitialized,
|
|
type: type,
|
|
),
|
|
)
|
|
.toList(),
|
|
);
|
|
}
|