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/config/brand_theme.dart';
|
|
|
|
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';
|
2022-10-11 20:11:13 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
2023-02-05 13:24:37 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
2022-12-31 04:16:10 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_button/outlined_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_cards/outlined_card.dart';
|
2022-10-11 20:11:13 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_md/brand_md.dart';
|
2022-12-31 04:16:10 +00:00
|
|
|
import 'package:selfprivacy/ui/components/info_box/info_box.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
|
2022-10-19 14:43:01 +00:00
|
|
|
Widget build(final BuildContext context) => Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-12-31 04:16:10 +00:00
|
|
|
"${'initializing.connect_to_server_provider'.tr()}${providerInfo.providerType.displayName}",
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.connect_to_server_provider_text'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
2022-10-19 14:43:01 +00:00
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
const SizedBox(height: 32),
|
2022-10-19 14:43:01 +00:00
|
|
|
CubitFormTextField(
|
|
|
|
formFieldCubit: providerCubit.apiKey,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
scrollPadding: const EdgeInsets.only(bottom: 70),
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
hintText: 'Provider API Token',
|
|
|
|
),
|
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
const SizedBox(height: 32),
|
2023-02-05 13:24:37 +00:00
|
|
|
BrandButton.filled(
|
|
|
|
child: Text('basis.connect'.tr()),
|
2022-10-20 14:36:15 +00:00
|
|
|
onPressed: () => providerCubit.trySubmit(),
|
2022-10-19 14:43:01 +00:00
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
2022-12-31 04:16:10 +00:00
|
|
|
BrandOutlinedButton(
|
2022-10-19 14:43:01 +00:00
|
|
|
child: Text('initializing.how'.tr()),
|
|
|
|
onPressed: () => showModalBottomSheet<void>(
|
|
|
|
context: context,
|
|
|
|
isScrollControlled: true,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
builder: (final BuildContext context) => BrandBottomSheet(
|
|
|
|
isExpended: true,
|
|
|
|
child: Padding(
|
|
|
|
padding: paddingH15V0,
|
|
|
|
child: ListView(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
|
|
children: [
|
|
|
|
BrandMarkdown(
|
|
|
|
fileName: providerInfo.pathToHow,
|
2022-10-11 20:11:13 +00:00
|
|
|
),
|
2022-10-19 14:43:01 +00:00
|
|
|
],
|
2022-10-11 20:11:13 +00:00
|
|
|
),
|
|
|
|
),
|
2022-10-19 14:43:01 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
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,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'initializing.connect_to_server'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
2022-10-11 20:11:13 +00:00
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
const SizedBox(height: 10),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
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',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 16),
|
|
|
|
Text(
|
|
|
|
'Hetzner Cloud',
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
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),
|
2023-02-05 13:24:37 +00:00
|
|
|
BrandButton.filled(
|
|
|
|
child: Text('basis.select'.tr()),
|
2022-12-31 04:16:10 +00:00
|
|
|
onPressed: () {
|
|
|
|
serverInstallationCubit
|
2023-01-30 15:44:52 +00:00
|
|
|
.setServerProviderType(ServerProviderType.hetzner);
|
|
|
|
callback(ServerProviderType.hetzner);
|
2022-12-31 04:16:10 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
// Outlined button that will open website
|
|
|
|
BrandOutlinedButton(
|
|
|
|
onPressed: () =>
|
2023-01-03 09:00:01 +00:00
|
|
|
launchURL('https://www.hetzner.com/cloud'),
|
2022-12-31 04:16:10 +00:00
|
|
|
title: 'initializing.select_provider_site_button'.tr(),
|
|
|
|
),
|
|
|
|
],
|
2022-10-11 20:11:13 +00:00
|
|
|
),
|
2022-12-31 04:16:10 +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',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 16),
|
|
|
|
Text(
|
|
|
|
'Digital Ocean',
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
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),
|
2023-02-05 13:24:37 +00:00
|
|
|
BrandButton.filled(
|
|
|
|
child: Text('basis.select'.tr()),
|
2022-12-31 04:16:10 +00:00
|
|
|
onPressed: () {
|
2023-01-30 15:44:52 +00:00
|
|
|
serverInstallationCubit.setServerProviderType(
|
|
|
|
ServerProviderType.digitalOcean);
|
|
|
|
callback(ServerProviderType.digitalOcean);
|
2022-12-31 04:16:10 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
// Outlined button that will open website
|
|
|
|
BrandOutlinedButton(
|
|
|
|
onPressed: () =>
|
2023-01-03 09:00:01 +00:00
|
|
|
launchURL('https://www.digitalocean.com'),
|
2022-12-31 04:16:10 +00:00
|
|
|
title: 'initializing.select_provider_site_button'.tr(),
|
|
|
|
),
|
|
|
|
],
|
2022-10-11 20:11:13 +00:00
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
),
|
2022-10-11 20:11:13 +00:00
|
|
|
),
|
2022-12-31 04:16:10 +00:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
InfoBox(text: 'initializing.select_provider_notice'.tr()),
|
|
|
|
],
|
|
|
|
),
|
2022-10-11 20:11:13 +00:00
|
|
|
);
|
|
|
|
}
|