Files
umbrix/lib/features/proxy/active/active_proxy_footer.dart

285 lines
12 KiB
Dart
Raw Normal View History

2024-02-09 12:02:52 +03:30
import 'package:dartx/dartx.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:hiddify/core/localization/translations.dart';
import 'package:hiddify/core/widget/animated_visibility.dart';
2024-02-11 00:29:09 +03:30
import 'package:hiddify/core/widget/shimmer_skeleton.dart';
2024-02-09 12:02:52 +03:30
import 'package:hiddify/features/proxy/active/active_proxy_notifier.dart';
2024-02-11 00:29:09 +03:30
import 'package:hiddify/features/proxy/active/ip_widget.dart';
2024-02-17 14:49:44 +03:30
import 'package:hiddify/features/proxy/model/proxy_failure.dart';
2024-02-09 12:02:52 +03:30
import 'package:hiddify/features/stats/notifier/stats_notifier.dart';
import 'package:hiddify/gen/fonts.gen.dart';
2024-02-09 12:02:52 +03:30
import 'package:hiddify/utils/utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class ActiveProxyFooter extends HookConsumerWidget {
const ActiveProxyFooter({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
final theme = Theme.of(context);
2024-02-13 16:59:35 +03:30
final activeProxy = ref.watch(activeProxyNotifierProvider);
final ipInfo = ref.watch(ipInfoNotifierProvider);
final stats = ref.watch(statsNotifierProvider).value;
2024-02-09 12:02:52 +03:30
return AnimatedVisibility(
axis: Axis.vertical,
2024-02-13 16:59:35 +03:30
visible: activeProxy is AsyncData,
child: switch (activeProxy) {
AsyncData(value: final proxy) => Padding(
2024-02-09 12:02:52 +03:30
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: Column(
2024-02-09 12:02:52 +03:30
children: [
// Карточка с информацией о прокси и локации
Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Название прокси
Row(
children: [
Icon(
FluentIcons.arrow_routing_20_regular,
size: 20,
color: theme.colorScheme.primary,
),
const Gap(12),
Expanded(
child: Text(
proxy.selectedName.isNotNullOrBlank
? proxy.selectedName!
: proxy.name,
semanticsLabel: t.proxies.activeProxySemanticLabel,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
fontFamily: FontFamily.emoji,
),
overflow: TextOverflow.ellipsis,
2024-02-11 00:29:09 +03:30
),
),
],
),
const Gap(12),
const Divider(height: 1),
const Gap(12),
// Информация о стране
switch (ipInfo) {
AsyncData(value: final info) => InkWell(
onTap: () async {
ref.read(ipInfoNotifierProvider.notifier).refresh();
},
borderRadius: BorderRadius.circular(8),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
IPCountryFlag(countryCode: info.countryCode),
const Gap(12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
info.countryCode.toUpperCase(),
style: theme.textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.w500,
),
),
if (info.org?.isNotEmpty ?? false)
Text(
info.org!,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
),
),
AsyncError(error: final UnknownIp _) => InkWell(
onTap: () async {
ref.read(ipInfoNotifierProvider.notifier).refresh();
},
borderRadius: BorderRadius.circular(8),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
const Icon(FluentIcons.arrow_sync_20_regular),
const Gap(12),
Text(
t.proxies.checkIp,
style: theme.textTheme.bodyMedium,
),
],
),
),
),
AsyncError() => InkWell(
onTap: () async {
ref.read(ipInfoNotifierProvider.notifier).refresh();
},
borderRadius: BorderRadius.circular(8),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
Icon(
FluentIcons.error_circle_20_regular,
color: theme.colorScheme.error,
),
const Gap(12),
Text(
t.proxies.unknownIp,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.error,
),
),
],
),
),
),
_ => const Padding(
padding: EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
Icon(FluentIcons.question_circle_20_regular),
Gap(12),
Expanded(
child: ShimmerSkeleton(height: 16, widthFactor: 0.6),
),
],
),
),
},
],
),
),
),
const Gap(12),
// Карточки со статистикой
Row(
children: [
Expanded(
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2024-02-17 14:49:44 +03:30
children: [
Icon(
FluentIcons.arrow_bidirectional_up_down_20_regular,
size: 24,
color: theme.colorScheme.secondary,
),
2024-02-17 14:49:44 +03:30
const Gap(8),
Text(
(stats?.downlinkTotal ?? 0).size(),
semanticsLabel: t.stats.totalTransferred,
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
Text(
t.stats.totalTransferred,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
2024-02-17 14:49:44 +03:30
),
],
),
),
),
),
const Gap(12),
Expanded(
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2024-02-17 12:32:11 +03:30
children: [
Icon(
FluentIcons.arrow_download_20_regular,
size: 24,
color: theme.colorScheme.tertiary,
),
2024-02-17 12:32:11 +03:30
const Gap(8),
Text(
(stats?.downlink ?? 0).speed(),
semanticsLabel: t.stats.speed,
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
2024-02-17 12:32:11 +03:30
),
Text(
t.stats.speed,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
2024-02-11 00:29:09 +03:30
),
),
],
2024-02-09 12:02:52 +03:30
),
),
),
),
],
2024-02-09 12:02:52 +03:30
),
],
),
),
_ => const SizedBox(),
},
);
}
}
class _InfoProp extends StatelessWidget {
2024-02-11 00:29:09 +03:30
const _InfoProp({
required this.icon,
required this.text,
2024-02-13 18:49:58 +03:30
this.semanticLabel,
2024-02-11 00:29:09 +03:30
});
2024-02-09 12:02:52 +03:30
2024-02-11 00:29:09 +03:30
final IconData icon;
final String text;
2024-02-13 18:49:58 +03:30
final String? semanticLabel;
2024-02-09 12:02:52 +03:30
@override
Widget build(BuildContext context) {
2024-02-13 18:49:58 +03:30
return Semantics(
label: semanticLabel,
child: Row(
children: [
Icon(icon),
const Gap(8),
Flexible(
child: Text(
text,
style: Theme.of(context)
.textTheme
.labelMedium
?.copyWith(fontFamily: FontFamily.emoji),
2024-02-13 18:49:58 +03:30
overflow: TextOverflow.ellipsis,
),
2024-02-11 00:29:09 +03:30
),
2024-02-13 18:49:58 +03:30
],
),
2024-02-09 12:02:52 +03:30
);
}
}