2024-02-10 17:32:45 +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';
|
2024-02-11 00:29:09 +03:30
|
|
|
import 'package:hiddify/core/widget/shimmer_skeleton.dart';
|
2024-02-10 17:32:45 +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-03-08 14:16:56 +01:00
|
|
|
import 'package:hiddify/gen/fonts.gen.dart';
|
2024-02-10 17:32:45 +03:30
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
|
|
|
|
|
class ActiveProxySideBarCard extends HookConsumerWidget {
|
|
|
|
|
const ActiveProxySideBarCard({super.key});
|
|
|
|
|
|
|
|
|
|
Widget buildProp(Widget icon, Widget child) {
|
|
|
|
|
return Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
icon,
|
|
|
|
|
const Gap(4),
|
|
|
|
|
Flexible(child: child),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
final t = ref.watch(translationsProvider);
|
2024-02-13 16:59:35 +03:30
|
|
|
final activeProxy = ref.watch(activeProxyNotifierProvider);
|
|
|
|
|
final ipInfo = ref.watch(ipInfoNotifierProvider);
|
2024-02-10 17:32:45 +03:30
|
|
|
|
|
|
|
|
Widget propText(String txt) {
|
2024-02-11 00:29:09 +03:30
|
|
|
return Text(
|
|
|
|
|
txt,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
2024-03-08 14:16:56 +01:00
|
|
|
style:
|
|
|
|
|
theme.textTheme.bodySmall?.copyWith(fontFamily: FontFamily.emoji),
|
2024-02-11 00:29:09 +03:30
|
|
|
);
|
2024-02-10 17:32:45 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Theme(
|
|
|
|
|
data: theme.copyWith(
|
|
|
|
|
iconTheme: theme.iconTheme.copyWith(size: 14),
|
|
|
|
|
),
|
|
|
|
|
child: Card(
|
|
|
|
|
margin: EdgeInsets.zero,
|
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(t.home.stats.connection),
|
|
|
|
|
const Gap(4),
|
2024-02-13 16:59:35 +03:30
|
|
|
switch (activeProxy) {
|
|
|
|
|
AsyncData(value: final proxy) => buildProp(
|
2024-02-10 17:32:45 +03:30
|
|
|
const Icon(FluentIcons.arrow_routing_20_regular),
|
|
|
|
|
propText(
|
2024-02-13 16:59:35 +03:30
|
|
|
proxy.selectedName.isNotNullOrBlank
|
|
|
|
|
? proxy.selectedName!
|
|
|
|
|
: proxy.name,
|
2024-02-10 17:32:45 +03:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
_ => buildProp(
|
|
|
|
|
const Icon(FluentIcons.arrow_routing_20_regular),
|
|
|
|
|
propText("..."),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
const Gap(4),
|
2024-02-13 16:59:35 +03:30
|
|
|
switch (ipInfo) {
|
|
|
|
|
AsyncData(value: final info) => buildProp(
|
|
|
|
|
IPCountryFlag(
|
|
|
|
|
countryCode: info.countryCode,
|
|
|
|
|
size: 16,
|
|
|
|
|
),
|
|
|
|
|
IPText(
|
|
|
|
|
ip: info.ip,
|
|
|
|
|
onLongPress: () async {
|
|
|
|
|
ref.read(ipInfoNotifierProvider.notifier).refresh();
|
|
|
|
|
},
|
|
|
|
|
constrained: true,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
AsyncLoading() => buildProp(
|
|
|
|
|
const Icon(FluentIcons.question_circle_20_regular),
|
|
|
|
|
const ShimmerSkeleton(widthFactor: .85, height: 14),
|
|
|
|
|
),
|
2024-02-17 14:49:44 +03:30
|
|
|
AsyncError(error: final UnknownIp _) => buildProp(
|
|
|
|
|
const Icon(FluentIcons.arrow_sync_20_regular),
|
|
|
|
|
UnknownIPText(
|
|
|
|
|
text: t.proxies.checkIp,
|
|
|
|
|
onTap: () async {
|
|
|
|
|
ref.read(ipInfoNotifierProvider.notifier).refresh();
|
|
|
|
|
},
|
|
|
|
|
constrained: true,
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-02-13 16:59:35 +03:30
|
|
|
_ => buildProp(
|
|
|
|
|
const Icon(FluentIcons.error_circle_20_regular),
|
2024-02-17 14:49:44 +03:30
|
|
|
UnknownIPText(
|
|
|
|
|
text: t.proxies.unknownIp,
|
|
|
|
|
onTap: () async {
|
2024-02-17 12:32:11 +03:30
|
|
|
ref.read(ipInfoNotifierProvider.notifier).refresh();
|
|
|
|
|
},
|
|
|
|
|
constrained: true,
|
|
|
|
|
),
|
2024-02-13 16:59:35 +03:30
|
|
|
),
|
|
|
|
|
},
|
2024-02-10 17:32:45 +03:30
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|