selfprivacy.org.app/lib/logic/cubit/app_config/app_config_state.dart

158 lines
4.7 KiB
Dart
Raw Normal View History

2021-01-06 17:35:57 +00:00
part of 'app_config_cubit.dart';
class AppConfigState extends Equatable {
const AppConfigState({
2021-03-15 15:39:44 +00:00
required this.hetznerKey,
required this.cloudFlareKey,
required this.backblazeCredential,
required this.cloudFlareDomain,
required this.rootUser,
required this.hetznerServer,
required this.isServerStarted,
2021-03-31 11:37:39 +00:00
required this.isServerResetedFirstTime,
required this.isServerResetedSecondTime,
2021-03-15 15:39:44 +00:00
required this.hasFinalChecked,
required this.isLoading,
required this.error,
2021-01-06 17:35:57 +00:00
});
@override
2021-03-15 15:39:44 +00:00
List<Object?> get props => [
2021-01-06 17:35:57 +00:00
hetznerKey,
cloudFlareKey,
2021-02-03 20:26:38 +00:00
backblazeCredential,
2021-01-06 17:35:57 +00:00
cloudFlareDomain,
rootUser,
2021-01-21 07:35:38 +00:00
hetznerServer,
2021-02-16 18:48:15 +00:00
isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime,
2021-02-16 18:48:15 +00:00
hasFinalChecked,
2021-01-06 17:35:57 +00:00
isLoading,
2021-01-19 12:05:40 +00:00
error,
2021-01-06 17:35:57 +00:00
];
2021-03-15 15:39:44 +00:00
final String? hetznerKey;
final String? cloudFlareKey;
final BackblazeCredential? backblazeCredential;
final CloudFlareDomain? cloudFlareDomain;
final User? rootUser;
final HetznerServerDetails? hetznerServer;
2021-03-23 19:50:11 +00:00
final bool isServerStarted;
2021-03-31 11:37:39 +00:00
final bool isServerResetedFirstTime;
final bool isServerResetedSecondTime;
2021-03-23 19:50:11 +00:00
final bool hasFinalChecked;
2021-02-16 18:48:15 +00:00
2021-03-15 15:39:44 +00:00
final bool? isLoading;
final Exception? error;
2021-01-06 17:35:57 +00:00
AppConfigState copyWith({
2021-03-15 15:39:44 +00:00
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
CloudFlareDomain? cloudFlareDomain,
User? rootUser,
HetznerServerDetails? hetznerServer,
bool? isServerStarted,
2021-03-31 11:37:39 +00:00
bool? isServerResetedFirstTime,
bool? isServerResetedSecondTime,
2021-03-15 15:39:44 +00:00
bool? hasFinalChecked,
bool? isLoading,
Exception? error,
2021-01-06 17:35:57 +00:00
}) =>
AppConfigState(
hetznerKey: hetznerKey ?? this.hetznerKey,
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
2021-02-03 20:26:38 +00:00
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
2021-01-21 07:35:38 +00:00
cloudFlareDomain: cloudFlareDomain ?? this.cloudFlareDomain,
2021-01-06 17:35:57 +00:00
rootUser: rootUser ?? this.rootUser,
2021-01-21 07:35:38 +00:00
hetznerServer: hetznerServer ?? this.hetznerServer,
2021-01-21 21:01:42 +00:00
isServerStarted: isServerStarted ?? this.isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime:
isServerResetedFirstTime ?? this.isServerResetedFirstTime,
isServerResetedSecondTime:
isServerResetedSecondTime ?? this.isServerResetedSecondTime,
2021-02-16 18:48:15 +00:00
hasFinalChecked: hasFinalChecked ?? this.hasFinalChecked,
2021-01-06 17:35:57 +00:00
isLoading: isLoading ?? this.isLoading,
2021-01-06 19:25:53 +00:00
error: error ?? this.error,
2021-01-06 17:35:57 +00:00
);
bool get isHetznerFilled => hetznerKey != null;
bool get isCloudFlareFilled => cloudFlareKey != null;
2021-02-03 20:26:38 +00:00
bool get isBackblazeFilled => backblazeCredential != null;
2021-01-06 17:35:57 +00:00
bool get isDomainFilled => cloudFlareDomain != null;
bool get isUserFilled => rootUser != null;
2021-02-16 18:48:15 +00:00
bool get isServerCreated => hetznerServer != null;
2021-01-21 21:01:42 +00:00
2021-03-15 15:39:44 +00:00
bool get isFullyInitilized => _fulfilementList.every((el) => el!);
int get progress => _fulfilementList.where((el) => el!).length;
2021-01-06 17:35:57 +00:00
2021-03-25 08:32:00 +00:00
List<bool?> get _fulfilementList {
var res = [
isHetznerFilled,
isCloudFlareFilled,
isBackblazeFilled,
isDomainFilled,
isUserFilled,
isServerCreated,
isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime,
isServerResetedSecondTime,
2021-03-25 08:32:00 +00:00
hasFinalChecked,
];
2021-03-30 17:38:40 +00:00
2021-03-25 08:32:00 +00:00
return res;
}
2021-01-06 17:35:57 +00:00
}
class InitialAppConfigState extends AppConfigState {
2021-02-16 18:48:15 +00:00
InitialAppConfigState()
: super(
hetznerKey: null,
cloudFlareKey: null,
backblazeCredential: null,
cloudFlareDomain: null,
rootUser: null,
hetznerServer: null,
isServerStarted: false,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime: false,
isServerResetedSecondTime: false,
2021-02-16 18:48:15 +00:00
hasFinalChecked: false,
isLoading: false,
error: null,
);
2021-01-06 17:35:57 +00:00
}
2021-02-15 18:58:29 +00:00
class TimerState extends AppConfigState {
TimerState({
2021-03-15 15:39:44 +00:00
required this.dataState,
2021-02-15 18:58:29 +00:00
this.timerStart,
this.duration,
2021-03-15 15:39:44 +00:00
required bool isLoading,
2021-02-16 18:48:15 +00:00
}) : super(
hetznerKey: dataState.hetznerKey,
cloudFlareKey: dataState.cloudFlareKey,
backblazeCredential: dataState.backblazeCredential,
cloudFlareDomain: dataState.cloudFlareDomain,
rootUser: dataState.rootUser,
hetznerServer: dataState.hetznerServer,
isServerStarted: dataState.isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime: dataState.isServerResetedFirstTime,
isServerResetedSecondTime: dataState.isServerResetedSecondTime,
2021-02-16 18:48:15 +00:00
hasFinalChecked: dataState.hasFinalChecked,
isLoading: isLoading,
error: dataState.error,
);
2021-02-15 18:58:29 +00:00
final AppConfigState dataState;
2021-03-15 15:39:44 +00:00
final DateTime? timerStart;
final Duration? duration;
2021-02-15 18:58:29 +00:00
@override
2021-03-15 15:39:44 +00:00
List<Object?> get props => [
2021-02-15 18:58:29 +00:00
dataState,
timerStart,
duration,
];
}