hiddify-next/lib/features/proxy/active/active_proxy_delay_indicator.dart
2024-02-13 19:59:17 +03:30

74 lines
2.7 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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';
import 'package:hiddify/core/widget/shimmer_skeleton.dart';
import 'package:hiddify/features/proxy/active/active_proxy_notifier.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class ActiveProxyDelayIndicator extends HookConsumerWidget {
const ActiveProxyDelayIndicator({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
final theme = Theme.of(context);
final activeProxy = ref.watch(activeProxyNotifierProvider);
return AnimatedVisibility(
axis: Axis.vertical,
visible: activeProxy is AsyncData,
child: () {
switch (activeProxy) {
case AsyncData(value: final proxy):
final delay = proxy.urlTestDelay;
return Center(
child: InkWell(
onTap: () async {
await ref
.read(activeProxyNotifierProvider.notifier)
.urlTest(proxy.tag);
},
borderRadius: BorderRadius.circular(24),
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(FluentIcons.wifi_1_24_regular),
const Gap(8),
if (delay > 0)
Text.rich(
semanticsLabel:
t.proxies.delaySemantics.result(delay: delay),
TextSpan(
children: [
TextSpan(
text: delay > 65000 ? "×" : delay.toString(),
style: theme.textTheme.titleMedium
?.copyWith(fontWeight: FontWeight.bold),
),
const TextSpan(text: " ms"),
],
),
)
else
Semantics(
label: t.proxies.delaySemantics.testing,
child: const ShimmerSkeleton(width: 48, height: 18),
),
],
),
),
),
);
default:
return const SizedBox();
}
}(),
);
}
}