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

205 lines
6.7 KiB
Dart
Raw Normal View History

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/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';
import 'package:selfprivacy/ui/components/brand_cards/filled_card.dart';
2022-02-16 07:09:53 +00:00
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
class DnsDetailsPage extends StatefulWidget {
const DnsDetailsPage({final 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.states.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.states.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.states.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.states.error'.tr();
subtitle = 'domain.states.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>[
2022-09-08 07:53:25 +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(
'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.name,
),
),
],
),
)
.toList(),
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(),
),
),
],
),
)
.toList(),
2022-02-16 07:09:53 +00:00
],
);
}
}