2022-10-11 20:11:13 +00:00
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-12-31 04:16:10 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2022-10-11 20:11:13 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
2022-12-30 03:25:18 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/server_provider_form_cubit.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/support_system/support_system_cubit.dart';
|
2022-10-11 20:11:13 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
2023-03-27 17:02:44 +00:00
|
|
|
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/buttons/outlined_button.dart';
|
2023-04-05 10:33:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/cards/outlined_card.dart';
|
2022-12-31 04:16:10 +00:00
|
|
|
import 'package:selfprivacy/ui/components/info_box/info_box.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/ui/layouts/responsive_layout_with_infobox.dart';
|
2023-01-17 13:23:26 +00:00
|
|
|
import 'package:selfprivacy/utils/launch_url.dart';
|
2022-10-11 20:11:13 +00:00
|
|
|
|
2022-10-15 19:49:31 +00:00
|
|
|
class ServerProviderPicker extends StatefulWidget {
|
|
|
|
const ServerProviderPicker({
|
2022-10-19 14:43:01 +00:00
|
|
|
required this.formCubit,
|
|
|
|
required this.serverInstallationCubit,
|
2022-10-11 20:11:13 +00:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
2022-12-30 03:25:18 +00:00
|
|
|
final ServerProviderFormCubit formCubit;
|
2022-10-19 14:43:01 +00:00
|
|
|
final ServerInstallationCubit serverInstallationCubit;
|
|
|
|
|
2022-10-11 20:11:13 +00:00
|
|
|
@override
|
2022-10-15 19:49:31 +00:00
|
|
|
State<ServerProviderPicker> createState() => _ServerProviderPickerState();
|
2022-10-11 20:11:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 19:49:31 +00:00
|
|
|
class _ServerProviderPickerState extends State<ServerProviderPicker> {
|
2023-01-30 15:44:52 +00:00
|
|
|
ServerProviderType selectedProvider = ServerProviderType.unknown;
|
2022-10-11 20:11:13 +00:00
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
void setProvider(final ServerProviderType provider) {
|
2022-10-11 20:11:13 +00:00
|
|
|
setState(() {
|
|
|
|
selectedProvider = provider;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
switch (selectedProvider) {
|
2023-01-30 15:44:52 +00:00
|
|
|
case ServerProviderType.unknown:
|
2022-10-11 20:11:13 +00:00
|
|
|
return ProviderSelectionPage(
|
2022-10-19 14:43:01 +00:00
|
|
|
serverInstallationCubit: widget.serverInstallationCubit,
|
2022-10-11 20:11:13 +00:00
|
|
|
callback: setProvider,
|
|
|
|
);
|
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
case ServerProviderType.hetzner:
|
2022-10-11 20:11:13 +00:00
|
|
|
return ProviderInputDataPage(
|
2022-10-19 14:43:01 +00:00
|
|
|
providerCubit: widget.formCubit,
|
2022-10-11 20:11:13 +00:00
|
|
|
providerInfo: ProviderPageInfo(
|
2023-01-30 15:44:52 +00:00
|
|
|
providerType: ServerProviderType.hetzner,
|
2022-12-31 06:01:27 +00:00
|
|
|
pathToHow: 'how_hetzner',
|
2022-10-11 20:11:13 +00:00
|
|
|
image: Image.asset(
|
|
|
|
'assets/images/logos/hetzner.png',
|
|
|
|
width: 150,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
case ServerProviderType.digitalOcean:
|
2022-10-11 20:11:13 +00:00
|
|
|
return ProviderInputDataPage(
|
2022-10-19 14:43:01 +00:00
|
|
|
providerCubit: widget.formCubit,
|
2022-10-11 20:11:13 +00:00
|
|
|
providerInfo: ProviderPageInfo(
|
2023-01-30 15:44:52 +00:00
|
|
|
providerType: ServerProviderType.digitalOcean,
|
2022-12-31 06:01:27 +00:00
|
|
|
pathToHow: 'how_digital_ocean',
|
2022-10-11 20:11:13 +00:00
|
|
|
image: Image.asset(
|
|
|
|
'assets/images/logos/digital_ocean.png',
|
|
|
|
width: 150,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProviderPageInfo {
|
|
|
|
const ProviderPageInfo({
|
|
|
|
required this.providerType,
|
|
|
|
required this.pathToHow,
|
|
|
|
required this.image,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String pathToHow;
|
|
|
|
final Image image;
|
2023-01-30 15:44:52 +00:00
|
|
|
final ServerProviderType providerType;
|
2022-10-11 20:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ProviderInputDataPage extends StatelessWidget {
|
|
|
|
const ProviderInputDataPage({
|
|
|
|
required this.providerInfo,
|
2022-10-19 14:43:01 +00:00
|
|
|
required this.providerCubit,
|
2022-10-11 20:11:13 +00:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final ProviderPageInfo providerInfo;
|
2022-12-30 03:25:18 +00:00
|
|
|
final ServerProviderFormCubit providerCubit;
|
2022-10-11 20:11:13 +00:00
|
|
|
|
|
|
|
@override
|
2023-02-23 14:49:14 +00:00
|
|
|
Widget build(final BuildContext context) => ResponsiveLayoutWithInfobox(
|
|
|
|
topChild: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"${'initializing.connect_to_server_provider'.tr()}${providerInfo.providerType.displayName}",
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
2022-10-19 14:43:01 +00:00
|
|
|
),
|
2023-02-23 14:49:14 +00:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.connect_to_server_provider_text'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
primaryColumn: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
CubitFormTextField(
|
2023-08-11 02:21:45 +00:00
|
|
|
autofocus: true,
|
2023-02-23 14:49:14 +00:00
|
|
|
formFieldCubit: providerCubit.apiKey,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
scrollPadding: const EdgeInsets.only(bottom: 70),
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
hintText: 'Provider API Token',
|
2022-10-19 14:43:01 +00:00
|
|
|
),
|
|
|
|
),
|
2023-02-23 14:49:14 +00:00
|
|
|
const SizedBox(height: 32),
|
|
|
|
BrandButton.filled(
|
|
|
|
child: Text('basis.connect'.tr()),
|
|
|
|
onPressed: () => providerCubit.trySubmit(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
BrandOutlinedButton(
|
|
|
|
child: Text('initializing.how'.tr()),
|
|
|
|
onPressed: () {
|
|
|
|
context.read<SupportSystemCubit>().showArticle(
|
|
|
|
article: providerInfo.pathToHow,
|
|
|
|
context: context,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-10-11 20:11:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProviderSelectionPage extends StatelessWidget {
|
|
|
|
const ProviderSelectionPage({
|
|
|
|
required this.callback,
|
2022-10-19 14:43:01 +00:00
|
|
|
required this.serverInstallationCubit,
|
2022-10-11 20:11:13 +00:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final Function callback;
|
2022-10-19 14:43:01 +00:00
|
|
|
final ServerInstallationCubit serverInstallationCubit;
|
2022-10-11 20:11:13 +00:00
|
|
|
|
|
|
|
@override
|
2022-12-31 04:16:10 +00:00
|
|
|
Widget build(final BuildContext context) => SizedBox(
|
|
|
|
width: double.infinity,
|
2023-02-23 14:49:14 +00:00
|
|
|
child: ResponsiveLayoutWithInfobox(
|
|
|
|
topChild: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'initializing.connect_to_server'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
primaryColumn: Column(
|
|
|
|
children: [
|
|
|
|
OutlinedCard(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 40,
|
|
|
|
height: 40,
|
|
|
|
padding: const EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(40),
|
|
|
|
color: const Color(0xFFD50C2D),
|
|
|
|
),
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
'assets/images/logos/hetzner.svg',
|
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
),
|
2023-02-23 14:49:14 +00:00
|
|
|
const SizedBox(width: 16),
|
|
|
|
Text(
|
|
|
|
'Hetzner Cloud',
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
2022-12-31 04:16:10 +00:00
|
|
|
),
|
2023-02-23 14:49:14 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_countries_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_countries_text_hetzner'
|
|
|
|
.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_price_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_price_text_hetzner'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_payment_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_payment_text_hetzner'
|
|
|
|
.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_email_notice'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
BrandButton.filled(
|
|
|
|
child: Text('basis.select'.tr()),
|
|
|
|
onPressed: () {
|
2023-04-12 08:32:56 +00:00
|
|
|
serverInstallationCubit.setServerProviderType(
|
|
|
|
ServerProviderType.hetzner,
|
|
|
|
);
|
|
|
|
callback(ServerProviderType.hetzner);
|
2023-02-23 14:49:14 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
// Outlined button that will open website
|
|
|
|
BrandOutlinedButton(
|
|
|
|
onPressed: () =>
|
|
|
|
launchURL('https://www.hetzner.com/cloud'),
|
|
|
|
title: 'initializing.select_provider_site_button'.tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-10-11 20:11:13 +00:00
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
),
|
2023-02-23 14:49:14 +00:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
OutlinedCard(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 40,
|
|
|
|
height: 40,
|
|
|
|
padding: const EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(40),
|
|
|
|
color: const Color(0xFF0080FF),
|
|
|
|
),
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
'assets/images/logos/digital_ocean.svg',
|
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
),
|
2023-02-23 14:49:14 +00:00
|
|
|
const SizedBox(width: 16),
|
|
|
|
Text(
|
|
|
|
'Digital Ocean',
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
2022-12-31 04:16:10 +00:00
|
|
|
),
|
2023-02-23 14:49:14 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_countries_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_countries_text_do'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_price_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_price_text_do'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_payment_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_payment_text_do'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
BrandButton.filled(
|
|
|
|
child: Text('basis.select'.tr()),
|
|
|
|
onPressed: () {
|
|
|
|
serverInstallationCubit.setServerProviderType(
|
2023-04-12 08:32:56 +00:00
|
|
|
ServerProviderType.digitalOcean,
|
2023-02-23 14:49:14 +00:00
|
|
|
);
|
2023-04-12 08:32:56 +00:00
|
|
|
callback(ServerProviderType.digitalOcean);
|
2023-02-23 14:49:14 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
// Outlined button that will open website
|
|
|
|
BrandOutlinedButton(
|
|
|
|
onPressed: () =>
|
|
|
|
launchURL('https://www.digitalocean.com'),
|
|
|
|
title: 'initializing.select_provider_site_button'.tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-10-11 20:11:13 +00:00
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
),
|
2023-02-23 14:49:14 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
secondaryColumn:
|
|
|
|
InfoBox(text: 'initializing.select_provider_notice'.tr()),
|
2022-12-31 04:16:10 +00:00
|
|
|
),
|
2022-10-11 20:11:13 +00:00
|
|
|
);
|
|
|
|
}
|