Files
umbrix/lib/features/proxies/widgets/proxy_tile.dart

80 lines
2.2 KiB
Dart
Raw Normal View History

2023-07-06 17:18:41 +03:30
import 'package:flutter/material.dart';
import 'package:hiddify/domain/clash/clash.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
// TODO: rewrite
class ProxyTile extends HookConsumerWidget {
const ProxyTile(
this.proxy, {
super.key,
required this.selected,
required this.onSelect,
this.delay,
});
final ClashProxy proxy;
final bool selected;
final VoidCallback onSelect;
final int? delay;
@override
Widget build(BuildContext context, WidgetRef ref) {
2023-08-19 22:27:23 +03:30
final theme = Theme.of(context);
2023-07-06 17:18:41 +03:30
return ListTile(
title: Text(
2023-08-19 22:27:23 +03:30
switch (proxy) {
ClashProxyGroup(:final name) => name.toUpperCase(),
ClashProxyItem(:final name) => name,
},
2023-07-06 17:18:41 +03:30
overflow: TextOverflow.ellipsis,
),
2023-08-19 22:27:23 +03:30
leading: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Container(
width: 6,
height: double.maxFinite,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: selected ? theme.colorScheme.primary : Colors.transparent,
),
),
),
subtitle: Text.rich(
TextSpan(
children: [
TextSpan(text: proxy.type.label),
if (proxy.udp)
WidgetSpan(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: DecoratedBox(
decoration: BoxDecoration(
border: Border.all(
color: theme.colorScheme.tertiaryContainer,
),
borderRadius: BorderRadius.circular(6),
),
child: Text(
" UDP ",
style: TextStyle(
fontSize: theme.textTheme.labelSmall?.fontSize,
),
),
),
),
),
if (proxy case ClashProxyGroup(:final now)) ...[
TextSpan(text: " ($now)"),
],
],
),
),
2023-07-06 17:18:41 +03:30
trailing: delay != null ? Text(delay.toString()) : null,
selected: selected,
onTap: onSelect,
2023-08-19 22:27:23 +03:30
horizontalTitleGap: 4,
2023-07-06 17:18:41 +03:30
);
}
}