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';
|
2024-12-06 18:42:43 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2022-02-16 07:09:53 +00:00
|
|
|
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-02-16 07:09:53 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/dns_records/dns_records_cubit.dart';
|
2024-01-31 05:14:23 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2024-05-15 14:16:59 +00:00
|
|
|
import 'package:selfprivacy/logic/get_it/resources_model.dart';
|
2024-11-06 00:22:30 +00:00
|
|
|
import 'package:selfprivacy/ui/atoms/icons/brand_icons.dart';
|
2024-12-06 18:42:43 +00:00
|
|
|
import 'package:selfprivacy/ui/atoms/list_tiles/section_headline.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
|
2024-12-06 18:42:43 +00:00
|
|
|
import 'package:selfprivacy/ui/molecules/cards/dns_state_card.dart';
|
|
|
|
import 'package:selfprivacy/ui/molecules/list_items/dns_record_item.dart';
|
|
|
|
import 'package:selfprivacy/utils/fake_data.dart';
|
|
|
|
import 'package:skeletonizer/skeletonizer.dart';
|
2022-02-16 07:09:53 +00:00
|
|
|
|
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> {
|
|
|
|
@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 =
|
2024-05-15 14:16:59 +00:00
|
|
|
getIt<ResourcesModel>().serverDomain?.domainName ?? '';
|
2022-06-05 19:36:32 +00:00
|
|
|
final DnsRecordsState dnsCubit = context.watch<DnsRecordsCubit>().state;
|
2024-12-06 18:42:43 +00:00
|
|
|
final List<DesiredDnsRecord> dnsRecords =
|
|
|
|
context.watch<DnsRecordsCubit>().state.dnsRecords;
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-06 18:42:43 +00:00
|
|
|
final recordsToShow =
|
|
|
|
dnsRecords.isEmpty ? FakeSelfPrivacyData.desiredDnsRecords : dnsRecords;
|
|
|
|
final refreshing =
|
|
|
|
dnsCubit.dnsState == DnsRecordsStatus.refreshing || dnsRecords.isEmpty;
|
|
|
|
|
|
|
|
List<Widget> recordsSection(
|
|
|
|
final String title,
|
|
|
|
final String subtitle,
|
|
|
|
final DnsRecordsCategory category,
|
|
|
|
) =>
|
|
|
|
[
|
|
|
|
SectionHeadline(
|
|
|
|
title: title,
|
|
|
|
subtitle: subtitle,
|
|
|
|
),
|
|
|
|
...recordsToShow
|
|
|
|
.where(
|
|
|
|
(final dnsRecord) => dnsRecord.category == category,
|
|
|
|
)
|
|
|
|
.map(
|
|
|
|
(final dnsRecord) => Skeletonizer(
|
|
|
|
enabled: refreshing,
|
2024-12-11 17:19:51 +00:00
|
|
|
enableSwitchAnimation: true,
|
2024-12-06 18:42:43 +00:00
|
|
|
child: DnsRecordItem(
|
|
|
|
dnsRecord: dnsRecord,
|
|
|
|
refreshing: refreshing,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
2022-09-08 07:53:25 +00:00
|
|
|
|
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>[
|
2024-12-06 18:42:43 +00:00
|
|
|
DnsStateCard(
|
|
|
|
dnsState: dnsCubit.dnsState,
|
|
|
|
fixCallback: () {
|
2023-01-11 18:01:46 +00:00
|
|
|
context.read<DnsRecordsCubit>().fix();
|
|
|
|
},
|
|
|
|
),
|
2024-12-06 18:42:43 +00:00
|
|
|
const Gap(8.0),
|
|
|
|
...recordsSection(
|
|
|
|
'domain.services_title'.tr(),
|
|
|
|
'domain.services_subtitle'.tr(),
|
|
|
|
DnsRecordsCategory.services,
|
2022-02-16 07:09:53 +00:00
|
|
|
),
|
2024-12-06 18:42:43 +00:00
|
|
|
const Gap(8.0),
|
|
|
|
...recordsSection(
|
|
|
|
'domain.email_title'.tr(),
|
|
|
|
'domain.email_subtitle'.tr(),
|
|
|
|
DnsRecordsCategory.email,
|
2022-02-16 07:09:53 +00:00
|
|
|
),
|
2024-12-06 18:42:43 +00:00
|
|
|
const Gap(8.0),
|
|
|
|
...recordsSection(
|
|
|
|
'domain.other_title'.tr(),
|
|
|
|
'domain.other_subtitle'.tr(),
|
|
|
|
DnsRecordsCategory.other,
|
2024-10-10 01:30:38 +00:00
|
|
|
),
|
2022-02-16 07:09:53 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|