2020-12-10 20:33:19 +00:00
|
|
|
part of 'providers_cubit.dart';
|
|
|
|
|
|
|
|
class ProvidersState extends Equatable {
|
|
|
|
const ProvidersState(this.all);
|
|
|
|
|
|
|
|
final List<ProviderModel> all;
|
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
ProvidersState updateElement(
|
|
|
|
final ProviderModel provider,
|
|
|
|
final StateType newState,
|
|
|
|
) {
|
2022-06-05 19:36:32 +00:00
|
|
|
final List<ProviderModel> newList = [...all];
|
|
|
|
final int index = newList.indexOf(provider);
|
2020-12-10 20:33:19 +00:00
|
|
|
newList[index] = provider.updateState(newState);
|
|
|
|
return ProvidersState(newList);
|
|
|
|
}
|
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
List<ProviderModel> get connected => all
|
|
|
|
.where((final service) => service.state != StateType.uninitialized)
|
|
|
|
.toList();
|
2020-12-10 20:33:19 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
List<ProviderModel> get uninitialized => all
|
|
|
|
.where((final service) => service.state == StateType.uninitialized)
|
|
|
|
.toList();
|
2020-12-10 20:33:19 +00:00
|
|
|
|
|
|
|
bool get isFullyInitialized => uninitialized.isEmpty;
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<Object> get props => all;
|
|
|
|
}
|
2020-12-30 14:13:25 +00:00
|
|
|
|
|
|
|
class InitialProviderState extends ProvidersState {
|
|
|
|
InitialProviderState()
|
|
|
|
: super(
|
|
|
|
ProviderType.values
|
|
|
|
.map(
|
2022-06-05 19:36:32 +00:00
|
|
|
(final type) => ProviderModel(
|
2020-12-30 14:13:25 +00:00
|
|
|
state: StateType.uninitialized,
|
|
|
|
type: type,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
);
|
|
|
|
}
|