2023-03-22 11:38:18 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-02-16 07:09:53 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:selfprivacy/config/get_it_config.dart';
|
2023-01-11 18:01:46 +00:00
|
|
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/desired_dns_record.dart';
|
2022-05-17 13:31:34 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2022-02-16 07:09:53 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/dns_records/dns_records_cubit.dart';
|
2023-04-05 10:33:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/cards/filled_card.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
|
2022-02-16 07:09:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2022-02-16 07:09:53 +00:00
|
|
|
class DnsDetailsPage extends StatefulWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const DnsDetailsPage({super.key});
|
2022-05-25 12:21:56 +00:00
|
|
|
|
2022-02-16 07:09:53 +00:00
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<DnsDetailsPage> createState() => _DnsDetailsPageState();
|
2022-02-16 07:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _DnsDetailsPageState extends State<DnsDetailsPage> {
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget _getStateCard(
|
|
|
|
final DnsRecordsStatus dnsState,
|
|
|
|
final Function fixCallback,
|
|
|
|
) {
|
2022-06-05 19:36:32 +00:00
|
|
|
String description = '';
|
|
|
|
String subtitle = '';
|
|
|
|
Icon icon = const Icon(
|
2022-09-08 07:53:25 +00:00
|
|
|
Icons.check_circle_outline,
|
|
|
|
size: 24.0,
|
2022-02-16 07:09:53 +00:00
|
|
|
);
|
2022-09-08 07:53:25 +00:00
|
|
|
bool isError = false;
|
2022-02-16 07:09:53 +00:00
|
|
|
switch (dnsState) {
|
|
|
|
case DnsRecordsStatus.uninitialized:
|
2022-10-24 12:19:39 +00:00
|
|
|
description = 'domain.uninitialized'.tr();
|
2022-05-24 18:55:39 +00:00
|
|
|
icon = const Icon(
|
2022-02-16 07:09:53 +00:00
|
|
|
Icons.refresh,
|
2022-09-08 07:53:25 +00:00
|
|
|
size: 24.0,
|
2022-02-16 07:09:53 +00:00
|
|
|
);
|
2022-09-08 07:53:25 +00:00
|
|
|
isError = false;
|
2022-02-16 07:09:53 +00:00
|
|
|
break;
|
|
|
|
case DnsRecordsStatus.refreshing:
|
2022-10-24 12:19:39 +00:00
|
|
|
description = 'domain.refreshing'.tr();
|
2022-05-24 18:55:39 +00:00
|
|
|
icon = const Icon(
|
2022-02-16 07:09:53 +00:00
|
|
|
Icons.refresh,
|
2022-09-08 07:53:25 +00:00
|
|
|
size: 24.0,
|
2022-02-16 07:09:53 +00:00
|
|
|
);
|
2022-09-08 07:53:25 +00:00
|
|
|
isError = false;
|
2022-02-16 07:09:53 +00:00
|
|
|
break;
|
|
|
|
case DnsRecordsStatus.good:
|
2022-10-24 12:19:39 +00:00
|
|
|
description = 'domain.ok'.tr();
|
2022-05-24 18:55:39 +00:00
|
|
|
icon = const Icon(
|
2022-09-08 07:53:25 +00:00
|
|
|
Icons.check_circle_outline,
|
|
|
|
size: 24.0,
|
2022-02-16 07:09:53 +00:00
|
|
|
);
|
2022-09-08 07:53:25 +00:00
|
|
|
isError = false;
|
2022-02-16 07:09:53 +00:00
|
|
|
break;
|
|
|
|
case DnsRecordsStatus.error:
|
2022-10-24 12:19:39 +00:00
|
|
|
description = 'domain.error'.tr();
|
|
|
|
subtitle = 'domain.error_subtitle'.tr();
|
2022-05-24 18:55:39 +00:00
|
|
|
icon = const Icon(
|
2022-09-08 07:53:25 +00:00
|
|
|
Icons.error_outline,
|
|
|
|
size: 24.0,
|
2022-02-16 07:09:53 +00:00
|
|
|
);
|
2022-09-08 07:53:25 +00:00
|
|
|
isError = true;
|
2022-02-16 07:09:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-09-15 16:57:26 +00:00
|
|
|
return FilledCard(
|
|
|
|
error: isError,
|
2022-09-08 07:53:25 +00:00
|
|
|
child: ListTile(
|
|
|
|
onTap: dnsState == DnsRecordsStatus.error ? () => fixCallback() : null,
|
|
|
|
leading: icon,
|
|
|
|
title: Text(description),
|
|
|
|
subtitle: subtitle != '' ? Text(subtitle) : null,
|
|
|
|
textColor: isError
|
|
|
|
? Theme.of(context).colorScheme.error
|
|
|
|
: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
iconColor: isError
|
|
|
|
? Theme.of(context).colorScheme.error
|
|
|
|
: Theme.of(context).colorScheme.onSurfaceVariant,
|
2022-02-16 07:09:53 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final bool isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2022-06-05 22:40:34 +00:00
|
|
|
final String domain =
|
|
|
|
getIt<ApiConfigModel>().serverDomain?.domainName ?? '';
|
2022-06-05 19:36:32 +00:00
|
|
|
final DnsRecordsState dnsCubit = context.watch<DnsRecordsCubit>().state;
|
2022-02-16 07:09:53 +00:00
|
|
|
|
|
|
|
print(dnsCubit.dnsState);
|
|
|
|
|
|
|
|
if (!isReady) {
|
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
|
|
|
heroIcon: BrandIcons.globe,
|
2022-10-03 23:32:35 +00:00
|
|
|
heroTitle: 'domain.screen_title'.tr(),
|
2022-09-16 14:14:29 +00:00
|
|
|
heroSubtitle: 'not_ready_card.in_menu'.tr(),
|
|
|
|
children: const [],
|
2022-02-16 07:09:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-08 07:53:25 +00:00
|
|
|
final Color goodColor = Theme.of(context).colorScheme.onBackground;
|
|
|
|
final Color errorColor = Theme.of(context).colorScheme.error;
|
|
|
|
final Color neutralColor = Theme.of(context).colorScheme.onBackground;
|
|
|
|
|
2022-02-16 07:09:53 +00:00
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
|
|
|
heroSubtitle: domain,
|
|
|
|
heroIcon: BrandIcons.globe,
|
2022-10-03 23:32:35 +00:00
|
|
|
heroTitle: 'domain.screen_title'.tr(),
|
2022-02-16 07:09:53 +00:00
|
|
|
children: <Widget>[
|
2023-01-11 18:01:46 +00:00
|
|
|
_getStateCard(
|
|
|
|
dnsCubit.dnsState,
|
|
|
|
() {
|
|
|
|
context.read<DnsRecordsCubit>().fix();
|
|
|
|
},
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16.0),
|
2022-09-08 07:53:25 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2022-10-03 23:32:35 +00:00
|
|
|
'domain.services_title'.tr(),
|
2022-09-08 07:53:25 +00:00
|
|
|
style: Theme.of(context).textTheme.headlineSmall!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2022-02-16 07:09:53 +00:00
|
|
|
),
|
2022-09-08 07:53:25 +00:00
|
|
|
),
|
|
|
|
subtitle: Text(
|
2022-10-03 23:32:35 +00:00
|
|
|
'domain.services_subtitle'.tr(),
|
2022-09-08 07:53:25 +00:00
|
|
|
style: Theme.of(context).textTheme.labelMedium,
|
2022-02-16 07:09:53 +00:00
|
|
|
),
|
|
|
|
),
|
2022-09-08 07:53:25 +00:00
|
|
|
...dnsCubit.dnsRecords
|
|
|
|
.where(
|
|
|
|
(final dnsRecord) =>
|
|
|
|
dnsRecord.category == DnsRecordsCategory.services,
|
|
|
|
)
|
|
|
|
.map(
|
|
|
|
(final dnsRecord) => Column(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
dnsRecord.isSatisfied
|
|
|
|
? Icons.check_circle_outline
|
|
|
|
: dnsCubit.dnsState == DnsRecordsStatus.refreshing
|
|
|
|
? Icons.refresh
|
|
|
|
: Icons.error_outline,
|
|
|
|
color: dnsRecord.isSatisfied
|
|
|
|
? goodColor
|
|
|
|
: dnsCubit.dnsState == DnsRecordsStatus.refreshing
|
|
|
|
? neutralColor
|
|
|
|
: errorColor,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
dnsRecord.description.tr(),
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
2023-01-11 18:01:46 +00:00
|
|
|
dnsRecord.displayName ?? dnsRecord.name,
|
2022-09-08 07:53:25 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-03-27 17:29:02 +00:00
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16.0),
|
2022-09-08 07:53:25 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text(
|
2022-10-03 23:32:35 +00:00
|
|
|
'domain.email_title'.tr(),
|
2022-09-08 07:53:25 +00:00
|
|
|
style: Theme.of(context).textTheme.headlineSmall!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2022-02-16 07:09:53 +00:00
|
|
|
),
|
2022-09-08 07:53:25 +00:00
|
|
|
),
|
|
|
|
subtitle: Text(
|
2022-10-03 23:32:35 +00:00
|
|
|
'domain.email_subtitle'.tr(),
|
2022-09-08 07:53:25 +00:00
|
|
|
style: Theme.of(context).textTheme.labelMedium,
|
2022-02-16 07:09:53 +00:00
|
|
|
),
|
|
|
|
),
|
2022-09-08 07:53:25 +00:00
|
|
|
...dnsCubit.dnsRecords
|
|
|
|
.where(
|
|
|
|
(final dnsRecord) =>
|
|
|
|
dnsRecord.category == DnsRecordsCategory.email,
|
|
|
|
)
|
|
|
|
.map(
|
|
|
|
(final dnsRecord) => Column(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
dnsRecord.isSatisfied
|
|
|
|
? Icons.check_circle_outline
|
|
|
|
: dnsCubit.dnsState == DnsRecordsStatus.refreshing
|
|
|
|
? Icons.refresh
|
|
|
|
: Icons.error_outline,
|
|
|
|
color: dnsRecord.isSatisfied
|
|
|
|
? goodColor
|
|
|
|
: dnsCubit.dnsState == DnsRecordsStatus.refreshing
|
|
|
|
? neutralColor
|
|
|
|
: errorColor,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
dnsRecord.description.tr(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-03-27 17:29:02 +00:00
|
|
|
),
|
2022-02-16 07:09:53 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|