2022-12-30 03:25:18 +00:00
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-01-03 09:00:01 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2022-12-30 03:25:18 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/cubit/forms/setup/initializing/dns_provider_form_cubit.dart';
|
2023-09-08 06:38:08 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/support_system/support_system_cubit.dart';
|
2022-12-30 03:25:18 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
2023-04-12 05:42:33 +00:00
|
|
|
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/buttons/outlined_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/cards/outlined_card.dart';
|
2023-05-17 16:58:15 +00:00
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
2022-12-30 03:25:18 +00:00
|
|
|
|
|
|
|
class DnsProviderPicker extends StatefulWidget {
|
|
|
|
const DnsProviderPicker({
|
|
|
|
required this.formCubit,
|
|
|
|
required this.serverInstallationCubit,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final DnsProviderFormCubit formCubit;
|
|
|
|
final ServerInstallationCubit serverInstallationCubit;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<DnsProviderPicker> createState() => _DnsProviderPickerState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DnsProviderPickerState extends State<DnsProviderPicker> {
|
2023-01-30 15:44:52 +00:00
|
|
|
DnsProviderType selectedProvider = DnsProviderType.unknown;
|
2022-12-30 03:25:18 +00:00
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
void setProvider(final DnsProviderType provider) {
|
2022-12-30 03:25:18 +00:00
|
|
|
setState(() {
|
|
|
|
selectedProvider = provider;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
switch (selectedProvider) {
|
2023-01-30 15:44:52 +00:00
|
|
|
case DnsProviderType.unknown:
|
2022-12-30 03:25:18 +00:00
|
|
|
return ProviderSelectionPage(
|
|
|
|
serverInstallationCubit: widget.serverInstallationCubit,
|
|
|
|
callback: setProvider,
|
|
|
|
);
|
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
case DnsProviderType.cloudflare:
|
2022-12-30 03:25:18 +00:00
|
|
|
return ProviderInputDataPage(
|
|
|
|
providerCubit: widget.formCubit,
|
2023-06-19 20:00:50 +00:00
|
|
|
providerInfo: const ProviderPageInfo(
|
2023-01-30 15:44:52 +00:00
|
|
|
providerType: DnsProviderType.cloudflare,
|
2022-12-30 03:25:18 +00:00
|
|
|
pathToHow: 'how_cloudflare',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-01-30 15:44:52 +00:00
|
|
|
case DnsProviderType.digitalOcean:
|
2022-12-30 03:25:18 +00:00
|
|
|
return ProviderInputDataPage(
|
|
|
|
providerCubit: widget.formCubit,
|
2023-06-19 20:00:50 +00:00
|
|
|
providerInfo: const ProviderPageInfo(
|
2023-01-30 15:44:52 +00:00
|
|
|
providerType: DnsProviderType.digitalOcean,
|
2023-01-03 09:00:01 +00:00
|
|
|
pathToHow: 'how_digital_ocean_dns',
|
2022-12-30 03:25:18 +00:00
|
|
|
),
|
|
|
|
);
|
2023-05-17 16:58:15 +00:00
|
|
|
|
|
|
|
case DnsProviderType.desec:
|
|
|
|
return ProviderInputDataPage(
|
|
|
|
providerCubit: widget.formCubit,
|
2023-06-19 20:00:50 +00:00
|
|
|
providerInfo: const ProviderPageInfo(
|
2023-05-17 16:58:15 +00:00
|
|
|
providerType: DnsProviderType.desec,
|
2023-05-16 18:03:31 +00:00
|
|
|
pathToHow: 'how_desec',
|
2023-05-09 06:15:48 +00:00
|
|
|
),
|
|
|
|
);
|
2022-12-30 03:25:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProviderPageInfo {
|
|
|
|
const ProviderPageInfo({
|
|
|
|
required this.providerType,
|
|
|
|
required this.pathToHow,
|
|
|
|
});
|
|
|
|
|
|
|
|
final String pathToHow;
|
2023-01-30 15:44:52 +00:00
|
|
|
final DnsProviderType providerType;
|
2022-12-30 03:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ProviderInputDataPage extends StatelessWidget {
|
|
|
|
const ProviderInputDataPage({
|
|
|
|
required this.providerInfo,
|
|
|
|
required this.providerCubit,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final ProviderPageInfo providerInfo;
|
|
|
|
final DnsProviderFormCubit providerCubit;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) => Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'initializing.connect_to_dns'.tr(),
|
2023-01-05 09:16:30 +00:00
|
|
|
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-12-30 03:25:18 +00:00
|
|
|
),
|
2023-01-05 09:16:30 +00:00
|
|
|
const SizedBox(height: 32),
|
2022-12-30 03:25:18 +00:00
|
|
|
CubitFormTextField(
|
2023-08-11 02:21:45 +00:00
|
|
|
autofocus: true,
|
2022-12-30 03:25:18 +00:00
|
|
|
formFieldCubit: providerCubit.apiKey,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
scrollPadding: const EdgeInsets.only(bottom: 70),
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
hintText: 'Provider API Token',
|
|
|
|
),
|
|
|
|
),
|
2023-01-05 09:16:30 +00:00
|
|
|
const SizedBox(height: 32),
|
2023-02-06 08:39:39 +00:00
|
|
|
BrandButton.rised(
|
|
|
|
text: 'basis.connect'.tr(),
|
2022-12-30 03:25:18 +00:00
|
|
|
onPressed: () => providerCubit.trySubmit(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
2023-01-05 09:16:30 +00:00
|
|
|
BrandOutlinedButton(
|
2022-12-30 03:25:18 +00:00
|
|
|
child: Text('initializing.how'.tr()),
|
2023-09-08 06:38:08 +00:00
|
|
|
onPressed: () => context.read<SupportSystemCubit>().showArticle(
|
|
|
|
article: providerInfo.pathToHow,
|
|
|
|
context: context,
|
2022-12-30 03:25:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProviderSelectionPage extends StatelessWidget {
|
|
|
|
const ProviderSelectionPage({
|
|
|
|
required this.callback,
|
|
|
|
required this.serverInstallationCubit,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final Function callback;
|
|
|
|
final ServerInstallationCubit serverInstallationCubit;
|
|
|
|
|
|
|
|
@override
|
2023-01-03 09:00:01 +00:00
|
|
|
Widget build(final BuildContext context) => SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2023-06-02 05:15:13 +00:00
|
|
|
|
|
|
|
/// TODO: Remove obvious repetition
|
2023-01-03 09:00:01 +00:00
|
|
|
children: [
|
|
|
|
Text(
|
2023-01-04 10:42:22 +00:00
|
|
|
'initializing.select_dns'.tr(),
|
2023-01-03 09:00:01 +00:00
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
2022-12-30 03:25:18 +00:00
|
|
|
),
|
2023-01-03 09:00:01 +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),
|
2023-05-18 22:06:13 +00:00
|
|
|
color: const Color.fromARGB(255, 245, 229, 82),
|
2023-01-03 09:00:01 +00:00
|
|
|
),
|
|
|
|
child: SvgPicture.asset(
|
2023-05-18 22:06:13 +00:00
|
|
|
'assets/images/logos/desec.svg',
|
2023-01-03 09:00:01 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 16),
|
|
|
|
Text(
|
2023-05-18 22:06:13 +00:00
|
|
|
'deSEC',
|
2023-01-03 09:00:01 +00:00
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_price_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
2023-01-04 10:42:22 +00:00
|
|
|
'initializing.select_provider_price_free'.tr(),
|
2023-01-03 09:00:01 +00:00
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
2023-02-06 08:39:39 +00:00
|
|
|
BrandButton.rised(
|
|
|
|
text: 'basis.select'.tr(),
|
2023-01-03 09:00:01 +00:00
|
|
|
onPressed: () {
|
|
|
|
serverInstallationCubit
|
2023-05-18 22:12:08 +00:00
|
|
|
.setDnsProviderType(DnsProviderType.desec);
|
|
|
|
callback(DnsProviderType.desec);
|
2023-01-03 09:00:01 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
// Outlined button that will open website
|
|
|
|
BrandOutlinedButton(
|
2023-05-18 22:12:08 +00:00
|
|
|
onPressed: () => launchUrlString('https://desec.io/'),
|
2023-01-03 09:00:01 +00:00
|
|
|
title: 'initializing.select_provider_site_button'.tr(),
|
|
|
|
),
|
|
|
|
],
|
2022-12-30 03:25:18 +00:00
|
|
|
),
|
2023-01-03 09:00:01 +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),
|
2023-05-18 22:06:13 +00:00
|
|
|
color: const Color.fromARGB(255, 244, 128, 31),
|
2023-01-03 09:00:01 +00:00
|
|
|
),
|
|
|
|
child: SvgPicture.asset(
|
2023-05-18 22:06:13 +00:00
|
|
|
'assets/images/logos/cloudflare.svg',
|
2023-01-03 09:00:01 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 16),
|
|
|
|
Text(
|
2023-05-18 22:06:13 +00:00
|
|
|
'Cloudflare',
|
2023-01-03 09:00:01 +00:00
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_price_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
2023-01-04 10:42:22 +00:00
|
|
|
'initializing.select_provider_price_free'.tr(),
|
2023-01-03 09:00:01 +00:00
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
2023-02-06 08:39:39 +00:00
|
|
|
BrandButton.rised(
|
|
|
|
text: 'basis.select'.tr(),
|
2023-01-03 09:00:01 +00:00
|
|
|
onPressed: () {
|
|
|
|
serverInstallationCubit
|
2023-05-18 22:12:08 +00:00
|
|
|
.setDnsProviderType(DnsProviderType.cloudflare);
|
|
|
|
callback(DnsProviderType.cloudflare);
|
2023-01-03 09:00:01 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
// Outlined button that will open website
|
|
|
|
BrandOutlinedButton(
|
|
|
|
onPressed: () =>
|
2023-05-18 22:12:08 +00:00
|
|
|
launchUrlString('https://dash.cloudflare.com/'),
|
2023-01-03 09:00:01 +00:00
|
|
|
title: 'initializing.select_provider_site_button'.tr(),
|
|
|
|
),
|
|
|
|
],
|
2022-12-30 03:25:18 +00:00
|
|
|
),
|
2023-01-03 09:00:01 +00:00
|
|
|
),
|
2022-12-30 03:25:18 +00:00
|
|
|
),
|
2023-06-02 05:15:13 +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.fromARGB(255, 1, 126, 251),
|
|
|
|
),
|
|
|
|
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_price_title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'initializing.select_provider_price_free'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
BrandButton.rised(
|
|
|
|
text: 'basis.select'.tr(),
|
|
|
|
onPressed: () {
|
|
|
|
serverInstallationCubit
|
|
|
|
.setDnsProviderType(DnsProviderType.digitalOcean);
|
|
|
|
callback(DnsProviderType.digitalOcean);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
// Outlined button that will open website
|
|
|
|
BrandOutlinedButton(
|
|
|
|
onPressed: () =>
|
|
|
|
launchUrlString('https://cloud.digitalocean.com/'),
|
|
|
|
title: 'initializing.select_provider_site_button'.tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-01-03 09:00:01 +00:00
|
|
|
],
|
|
|
|
),
|
2022-12-30 03:25:18 +00:00
|
|
|
);
|
|
|
|
}
|