selfprivacy.org.app/lib/ui/pages/dns_details/dns_details.dart

209 lines
6.8 KiB
Dart
Raw Normal View History

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';
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/desired_dns_record.dart';
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';
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';
@RoutePage()
2022-02-16 07:09:53 +00:00
class DnsDetailsPage extends StatefulWidget {
const DnsDetailsPage({super.key});
2022-02-16 07:09:53 +00:00
@override
State<DnsDetailsPage> createState() => _DnsDetailsPageState();
2022-02-16 07:09:53 +00:00
}
class _DnsDetailsPageState extends State<DnsDetailsPage> {
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:
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:
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:
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:
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;
}
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
is ServerInstallationFinished;
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,
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,
heroTitle: 'domain.screen_title'.tr(),
2022-02-16 07:09:53 +00:00
children: <Widget>[
_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(
'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(
'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(
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(
'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(
'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
],
);
}
}