mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-09 09:31:13 +00:00
refactor: Init blocs in initState and not in widget build
This commit is contained in:
parent
e330f71b63
commit
3222a9b500
|
@ -16,29 +16,52 @@ import 'package:selfprivacy/logic/cubit/server_volumes/server_volume_cubit.dart'
|
||||||
import 'package:selfprivacy/logic/cubit/support_system/support_system_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/support_system/support_system_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
||||||
|
|
||||||
class BlocAndProviderConfig extends StatelessWidget {
|
class BlocAndProviderConfig extends StatefulWidget {
|
||||||
const BlocAndProviderConfig({super.key, this.child});
|
const BlocAndProviderConfig({super.key, this.child});
|
||||||
|
|
||||||
final Widget? child;
|
final Widget? child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
BlocAndProviderConfigState createState() => BlocAndProviderConfigState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class BlocAndProviderConfigState extends State<BlocAndProviderConfig> {
|
||||||
|
late final ServerInstallationCubit serverInstallationCubit;
|
||||||
|
late final SupportSystemCubit supportSystemCubit;
|
||||||
|
late final UsersCubit usersCubit;
|
||||||
|
late final ServicesBloc servicesBloc;
|
||||||
|
late final BackupsBloc backupsBloc;
|
||||||
|
late final DnsRecordsCubit dnsRecordsCubit;
|
||||||
|
late final RecoveryKeyCubit recoveryKeyCubit;
|
||||||
|
late final ApiDevicesCubit apiDevicesCubit;
|
||||||
|
late final ApiProviderVolumeCubit apiVolumesCubit;
|
||||||
|
late final ApiServerVolumeCubit apiServerVolumesCubit;
|
||||||
|
late final ServerJobsBloc serverJobsBloc;
|
||||||
|
late final ConnectionStatusBloc connectionStatusBloc;
|
||||||
|
late final ServerDetailsCubit serverDetailsCubit;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
serverInstallationCubit = ServerInstallationCubit()..load();
|
||||||
|
supportSystemCubit = SupportSystemCubit();
|
||||||
|
usersCubit = UsersCubit();
|
||||||
|
servicesBloc = ServicesBloc();
|
||||||
|
backupsBloc = BackupsBloc();
|
||||||
|
dnsRecordsCubit = DnsRecordsCubit();
|
||||||
|
recoveryKeyCubit = RecoveryKeyCubit();
|
||||||
|
apiDevicesCubit = ApiDevicesCubit();
|
||||||
|
apiVolumesCubit = ApiProviderVolumeCubit();
|
||||||
|
apiServerVolumesCubit = ApiServerVolumeCubit(apiVolumesCubit);
|
||||||
|
serverJobsBloc = ServerJobsBloc();
|
||||||
|
connectionStatusBloc = ConnectionStatusBloc();
|
||||||
|
serverDetailsCubit = ServerDetailsCubit();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(final BuildContext context) {
|
Widget build(final BuildContext context) {
|
||||||
const isDark = false;
|
const isDark = false;
|
||||||
const isAutoDark = true;
|
const isAutoDark = true;
|
||||||
final serverInstallationCubit = ServerInstallationCubit()..load();
|
|
||||||
final supportSystemCubit = SupportSystemCubit();
|
|
||||||
final usersCubit = UsersCubit(serverInstallationCubit);
|
|
||||||
final servicesBloc = ServicesBloc();
|
|
||||||
final backupsBloc = BackupsBloc();
|
|
||||||
final dnsRecordsCubit = DnsRecordsCubit(serverInstallationCubit);
|
|
||||||
final recoveryKeyCubit = RecoveryKeyCubit(serverInstallationCubit);
|
|
||||||
final apiDevicesCubit = ApiDevicesCubit(serverInstallationCubit);
|
|
||||||
final apiVolumesCubit = ApiProviderVolumeCubit(serverInstallationCubit);
|
|
||||||
final apiServerVolumesCubit =
|
|
||||||
ApiServerVolumeCubit(serverInstallationCubit, apiVolumesCubit);
|
|
||||||
final serverJobsBloc = ServerJobsBloc();
|
|
||||||
final connectionStatusBloc = ConnectionStatusBloc();
|
|
||||||
final serverDetailsCubit = ServerDetailsCubit(serverInstallationCubit);
|
|
||||||
|
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
|
@ -57,7 +80,7 @@ class BlocAndProviderConfig extends StatelessWidget {
|
||||||
lazy: false,
|
lazy: false,
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (final _) => usersCubit..load(),
|
create: (final _) => usersCubit,
|
||||||
lazy: false,
|
lazy: false,
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
|
@ -70,23 +93,23 @@ class BlocAndProviderConfig extends StatelessWidget {
|
||||||
create: (final _) => dnsRecordsCubit,
|
create: (final _) => dnsRecordsCubit,
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (final _) => recoveryKeyCubit..load(),
|
create: (final _) => recoveryKeyCubit,
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (final _) => apiDevicesCubit..load(),
|
create: (final _) => apiDevicesCubit,
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (final _) => apiVolumesCubit..load(),
|
create: (final _) => apiVolumesCubit,
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (final _) => apiServerVolumesCubit..load(),
|
create: (final _) => apiServerVolumesCubit,
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (final _) => serverJobsBloc,
|
create: (final _) => serverJobsBloc,
|
||||||
),
|
),
|
||||||
BlocProvider(create: (final _) => connectionStatusBloc),
|
BlocProvider(create: (final _) => connectionStatusBloc),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (final _) => serverDetailsCubit..load(),
|
create: (final _) => serverDetailsCubit,
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (final _) => JobsCubit(
|
create: (final _) => JobsCubit(
|
||||||
|
@ -95,7 +118,7 @@ class BlocAndProviderConfig extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,7 @@ import 'package:selfprivacy/logic/models/json/api_token.dart';
|
||||||
part 'devices_state.dart';
|
part 'devices_state.dart';
|
||||||
|
|
||||||
class ApiDevicesCubit extends ServerConnectionDependentCubit<ApiDevicesState> {
|
class ApiDevicesCubit extends ServerConnectionDependentCubit<ApiDevicesState> {
|
||||||
ApiDevicesCubit(final ServerInstallationCubit serverInstallationCubit)
|
ApiDevicesCubit() : super(const ApiDevicesState.initial());
|
||||||
: super(const ApiDevicesState.initial());
|
|
||||||
|
|
||||||
final ServerApi api = ServerApi();
|
final ServerApi api = ServerApi();
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import 'package:selfprivacy/utils/network_utils.dart';
|
||||||
part 'dns_records_state.dart';
|
part 'dns_records_state.dart';
|
||||||
|
|
||||||
class DnsRecordsCubit extends ServerConnectionDependentCubit<DnsRecordsState> {
|
class DnsRecordsCubit extends ServerConnectionDependentCubit<DnsRecordsState> {
|
||||||
DnsRecordsCubit(final ServerInstallationCubit serverInstallationCubit)
|
DnsRecordsCubit()
|
||||||
: super(
|
: super(
|
||||||
const DnsRecordsState(dnsState: DnsRecordsStatus.refreshing),
|
const DnsRecordsState(dnsState: DnsRecordsStatus.refreshing),
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,8 +15,7 @@ part 'provider_volume_state.dart';
|
||||||
|
|
||||||
class ApiProviderVolumeCubit
|
class ApiProviderVolumeCubit
|
||||||
extends ServerConnectionDependentCubit<ApiProviderVolumeState> {
|
extends ServerConnectionDependentCubit<ApiProviderVolumeState> {
|
||||||
ApiProviderVolumeCubit(final ServerInstallationCubit serverInstallationCubit)
|
ApiProviderVolumeCubit() : super(const ApiProviderVolumeState.initial());
|
||||||
: super(const ApiProviderVolumeState.initial());
|
|
||||||
final ServerApi serverApi = ServerApi();
|
final ServerApi serverApi = ServerApi();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -9,8 +9,7 @@ part 'recovery_key_state.dart';
|
||||||
|
|
||||||
class RecoveryKeyCubit
|
class RecoveryKeyCubit
|
||||||
extends ServerConnectionDependentCubit<RecoveryKeyState> {
|
extends ServerConnectionDependentCubit<RecoveryKeyState> {
|
||||||
RecoveryKeyCubit(final ServerInstallationCubit serverInstallationCubit)
|
RecoveryKeyCubit() : super(const RecoveryKeyState.initial());
|
||||||
: super(const RecoveryKeyState.initial());
|
|
||||||
|
|
||||||
final ServerApi api = ServerApi();
|
final ServerApi api = ServerApi();
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,7 @@ part 'server_detailed_info_state.dart';
|
||||||
|
|
||||||
class ServerDetailsCubit
|
class ServerDetailsCubit
|
||||||
extends ServerConnectionDependentCubit<ServerDetailsState> {
|
extends ServerConnectionDependentCubit<ServerDetailsState> {
|
||||||
ServerDetailsCubit(final ServerInstallationCubit serverInstallationCubit)
|
ServerDetailsCubit() : super(ServerDetailsInitial());
|
||||||
: super(ServerDetailsInitial());
|
|
||||||
|
|
||||||
ServerDetailsRepository repository = ServerDetailsRepository();
|
ServerDetailsRepository repository = ServerDetailsRepository();
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ part 'server_volume_state.dart';
|
||||||
class ApiServerVolumeCubit
|
class ApiServerVolumeCubit
|
||||||
extends ServerConnectionDependentCubit<ApiServerVolumeState> {
|
extends ServerConnectionDependentCubit<ApiServerVolumeState> {
|
||||||
ApiServerVolumeCubit(
|
ApiServerVolumeCubit(
|
||||||
final ServerInstallationCubit serverInstallationCubit,
|
|
||||||
this.providerVolumeCubit,
|
this.providerVolumeCubit,
|
||||||
) : super(ApiServerVolumeState.initial()) {
|
) : super(ApiServerVolumeState.initial()) {
|
||||||
// TODO: Remove this connection between cubits
|
// TODO: Remove this connection between cubits
|
||||||
|
|
|
@ -13,7 +13,7 @@ export 'package:provider/provider.dart';
|
||||||
part 'users_state.dart';
|
part 'users_state.dart';
|
||||||
|
|
||||||
class UsersCubit extends ServerConnectionDependentCubit<UsersState> {
|
class UsersCubit extends ServerConnectionDependentCubit<UsersState> {
|
||||||
UsersCubit(final ServerInstallationCubit serverInstallationCubit)
|
UsersCubit()
|
||||||
: super(
|
: super(
|
||||||
const UsersState(
|
const UsersState(
|
||||||
<User>[],
|
<User>[],
|
||||||
|
|
Loading…
Reference in a new issue