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

113 lines
3.7 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:gap/gap.dart';
2022-02-16 07:09:53 +00:00
import 'package:selfprivacy/config/get_it_config.dart';
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';
import 'package:selfprivacy/logic/get_it/resources_model.dart';
import 'package:selfprivacy/ui/atoms/icons/brand_icons.dart';
import 'package:selfprivacy/ui/atoms/list_tiles/section_headline.dart';
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
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
@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> {
@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<ResourcesModel>().serverDomain?.domainName ?? '';
2022-06-05 19:36:32 +00:00
final DnsRecordsState dnsCubit = context.watch<DnsRecordsCubit>().state;
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,
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
);
}
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,
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,
heroTitle: 'domain.screen_title'.tr(),
2022-02-16 07:09:53 +00:00
children: <Widget>[
DnsStateCard(
dnsState: dnsCubit.dnsState,
fixCallback: () {
context.read<DnsRecordsCubit>().fix();
},
),
const Gap(8.0),
...recordsSection(
'domain.services_title'.tr(),
'domain.services_subtitle'.tr(),
DnsRecordsCategory.services,
2022-02-16 07:09:53 +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
),
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
],
);
}
}