Files
umbrix/lib/features/proxy/widget/proxy_tile.dart

87 lines
2.7 KiB
Dart
Raw Normal View History

2023-07-06 17:18:41 +03:30
import 'package:flutter/material.dart';
2023-12-01 12:56:24 +03:30
import 'package:hiddify/features/proxy/model/proxy_entity.dart';
2024-07-04 21:06:08 +02:00
import 'package:hiddify/gen/fonts.gen.dart';
2023-11-12 13:08:48 +03:30
import 'package:hiddify/utils/custom_loggers.dart';
2023-07-06 17:18:41 +03:30
import 'package:hooks_riverpod/hooks_riverpod.dart';
2023-11-12 13:08:48 +03:30
class ProxyTile extends HookConsumerWidget with PresLogger {
2023-07-06 17:18:41 +03:30
const ProxyTile(
this.proxy, {
super.key,
required this.selected,
required this.onSelect,
});
2023-12-01 12:56:24 +03:30
final ProxyItemEntity 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(
2023-12-01 12:56:24 +03:30
proxy.name,
2023-07-06 17:18:41 +03:30
overflow: TextOverflow.ellipsis,
2024-03-08 14:16:56 +01:00
style: TextStyle(fontFamily: FontFamily.emoji),
2023-07-06 17:18:41 +03:30
),
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: [
2023-12-01 12:56:24 +03:30
if (proxy.selectedName != null)
TextSpan(
2023-12-01 12:56:24 +03:30
text: ' (${proxy.selectedName})',
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(
2024-02-10 11:39:37 +01:00
proxy.urlTestDelay > 65000 ? "×" : proxy.urlTestDelay.toString(),
2023-10-27 13:03:27 +03:30
style: TextStyle(color: delayColor(context, proxy.urlTestDelay)),
)
: null,
2023-07-06 17:18:41 +03:30
selected: selected,
onTap: onSelect,
2023-11-12 13:08:48 +03:30
onLongPress: () async {
showDialog(
context: context,
builder: (context) => AlertDialog(
2023-12-01 12:56:24 +03:30
content: SelectionArea(child: Text(proxy.name)),
2023-11-12 13:08:48 +03:30
actions: [
TextButton(
onPressed: Navigator.of(context).pop,
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
),
],
),
);
},
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) {
2024-07-04 21:06:08 +02:00
return switch (delay) { < 800 => Colors.lightGreen, < 1500 => Colors.orange, _ => Colors.redAccent };
2023-10-27 13:03:27 +03:30
}
2024-07-04 21:06:08 +02:00
return switch (delay) { < 800 => Colors.green, < 1500 => Colors.deepOrangeAccent, _ => Colors.red };
2023-10-27 13:03:27 +03:30
}
2023-07-06 17:18:41 +03:30
}