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';
|
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';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
|
|
|
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 {
|
2022-06-05 22:40:34 +00:00
|
|
|
const DnsDetailsPage({final 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-02-16 07:09:53 +00:00
|
|
|
Icons.check,
|
|
|
|
color: Colors.green,
|
|
|
|
);
|
|
|
|
switch (dnsState) {
|
|
|
|
case DnsRecordsStatus.uninitialized:
|
|
|
|
description = 'providers.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,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case DnsRecordsStatus.refreshing:
|
|
|
|
description = 'providers.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,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case DnsRecordsStatus.good:
|
|
|
|
description = 'providers.domain.states.ok'.tr();
|
2022-05-24 18:55:39 +00:00
|
|
|
icon = const Icon(
|
2022-02-16 07:09:53 +00:00
|
|
|
Icons.check,
|
|
|
|
color: Colors.green,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case DnsRecordsStatus.error:
|
|
|
|
description = 'providers.domain.states.error'.tr();
|
|
|
|
subtitle = 'providers.domain.states.error_subtitle'.tr();
|
2022-05-24 18:55:39 +00:00
|
|
|
icon = const Icon(
|
2022-02-16 07:09:53 +00:00
|
|
|
Icons.error,
|
|
|
|
color: Colors.red,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ListTile(
|
|
|
|
onTap: dnsState == DnsRecordsStatus.error ? () => fixCallback() : null,
|
|
|
|
title: Text(
|
|
|
|
description,
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
subtitle: subtitle != '' ? Text(subtitle) : null,
|
|
|
|
leading: icon,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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,
|
|
|
|
headerTitle: '',
|
|
|
|
heroIcon: BrandIcons.globe,
|
|
|
|
heroTitle: 'providers.domain.screen_title'.tr(),
|
|
|
|
children: <Widget>[
|
|
|
|
BrandCards.outlined(
|
|
|
|
child: ListTile(
|
|
|
|
title: Text(
|
|
|
|
'not_ready_card.in_menu'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
|
|
|
heroSubtitle: domain,
|
|
|
|
heroIcon: BrandIcons.globe,
|
|
|
|
heroTitle: 'providers.domain.screen_title'.tr(),
|
|
|
|
children: <Widget>[
|
|
|
|
BrandCards.outlined(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
_getStateCard(dnsCubit.dnsState, () {
|
|
|
|
context.read<DnsRecordsCubit>().fix();
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16.0),
|
2022-02-16 07:09:53 +00:00
|
|
|
// Outlined card with a list of A records and their
|
|
|
|
// status.
|
|
|
|
BrandCards.outlined(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'providers.domain.cards.services.title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
'providers.domain.cards.services.subtitle'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.caption,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
...dnsCubit.dnsRecords
|
|
|
|
.where(
|
2022-06-05 19:36:32 +00:00
|
|
|
(final dnsRecord) =>
|
2022-02-16 07:09:53 +00:00
|
|
|
dnsRecord.category == DnsRecordsCategory.services,
|
|
|
|
)
|
|
|
|
.map(
|
2022-06-05 19:36:32 +00:00
|
|
|
(final dnsRecord) => Column(
|
2022-02-16 07:09:53 +00:00
|
|
|
children: [
|
2022-05-24 18:55:39 +00:00
|
|
|
const Divider(
|
2022-02-16 07:09:53 +00:00
|
|
|
height: 1.0,
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
dnsRecord.isSatisfied
|
|
|
|
? Icons.check
|
|
|
|
: dnsCubit.dnsState ==
|
|
|
|
DnsRecordsStatus.refreshing
|
|
|
|
? Icons.refresh
|
|
|
|
: Icons.error,
|
|
|
|
color: dnsRecord.isSatisfied
|
|
|
|
? Colors.green
|
|
|
|
: dnsCubit.dnsState ==
|
|
|
|
DnsRecordsStatus.refreshing
|
|
|
|
? Colors.grey
|
|
|
|
: Colors.red,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
dnsRecord.description.tr(),
|
|
|
|
style: Theme.of(context).textTheme.labelLarge,
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
dnsRecord.name,
|
|
|
|
style: Theme.of(context).textTheme.caption,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 16.0),
|
2022-02-16 07:09:53 +00:00
|
|
|
BrandCards.outlined(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
title: Text(
|
|
|
|
'providers.domain.cards.email.title'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.headline6,
|
|
|
|
),
|
|
|
|
subtitle: Text(
|
|
|
|
'providers.domain.cards.email.subtitle'.tr(),
|
|
|
|
style: Theme.of(context).textTheme.caption,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
...dnsCubit.dnsRecords
|
|
|
|
.where(
|
2022-06-05 19:36:32 +00:00
|
|
|
(final dnsRecord) =>
|
2022-02-16 07:09:53 +00:00
|
|
|
dnsRecord.category == DnsRecordsCategory.email,
|
|
|
|
)
|
|
|
|
.map(
|
2022-06-05 19:36:32 +00:00
|
|
|
(final dnsRecord) => Column(
|
2022-02-16 07:09:53 +00:00
|
|
|
children: [
|
2022-05-24 18:55:39 +00:00
|
|
|
const Divider(
|
2022-02-16 07:09:53 +00:00
|
|
|
height: 1.0,
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
leading: Icon(
|
|
|
|
dnsRecord.isSatisfied
|
|
|
|
? Icons.check
|
|
|
|
: dnsCubit.dnsState ==
|
|
|
|
DnsRecordsStatus.refreshing
|
|
|
|
? Icons.refresh
|
|
|
|
: Icons.error,
|
|
|
|
color: dnsRecord.isSatisfied
|
|
|
|
? Colors.green
|
|
|
|
: dnsCubit.dnsState ==
|
|
|
|
DnsRecordsStatus.refreshing
|
|
|
|
? Colors.grey
|
|
|
|
: Colors.red,
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
dnsRecord.description.tr(),
|
|
|
|
style: Theme.of(context).textTheme.labelLarge,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|