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

78 lines
2.1 KiB
Dart
Raw Normal View History

2023-07-06 17:18:41 +03:30
import 'package:flutter/material.dart';
2023-08-29 19:32:31 +03:30
import 'package:hiddify/domain/singbox/singbox.dart';
2023-07-06 17:18:41 +03:30
import 'package:hooks_riverpod/hooks_riverpod.dart';
class ProxyTile extends HookConsumerWidget {
const ProxyTile(
this.proxy, {
super.key,
required this.selected,
required this.onSelect,
});
2023-08-29 19:32:31 +03:30
final OutboundGroupItem proxy;
2023-07-06 17:18:41 +03:30
final bool selected;
final VoidCallback onSelect;
@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(
2023-08-25 13:29:39 +03:30
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
2023-07-06 17:18:41 +03:30
title: Text(
sanitizedTag(proxy.tag),
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(
text: proxy.type.label,
children: [
if (proxy.selectedTag != null)
TextSpan(
text: ' (${sanitizedTag(proxy.selectedTag!)})',
style: Theme.of(context).textTheme.bodySmall,
),
],
),
2023-08-25 13:29:39 +03:30
overflow: TextOverflow.ellipsis,
2023-08-19 22:27:23 +03:30
),
2023-10-27 13:03:27 +03:30
trailing: proxy.urlTestDelay != 0
? Text(
proxy.urlTestDelay.toString(),
style: TextStyle(color: delayColor(context, proxy.urlTestDelay)),
)
: null,
2023-07-06 17:18:41 +03:30
selected: selected,
onTap: onSelect,
2023-08-19 22:27:23 +03:30
horizontalTitleGap: 4,
2023-07-06 17:18:41 +03:30
);
}
2023-10-27 13:03:27 +03:30
Color delayColor(BuildContext context, int delay) {
if (Theme.of(context).brightness == Brightness.dark) {
return switch (delay) {
< 800 => Colors.lightGreen,
< 1500 => Colors.orange,
_ => Colors.redAccent
};
}
return switch (delay) {
< 800 => Colors.green,
< 1500 => Colors.deepOrangeAccent,
_ => Colors.red
};
}
2023-07-06 17:18:41 +03:30
}