adguard-home-manager/lib/screens/clients/active_client_tile.dart

169 lines
5.5 KiB
Dart
Raw Normal View History

2023-05-01 21:34:00 +02:00
import 'package:flutter/material.dart';
2023-05-04 22:38:37 +02:00
import 'package:contextmenu/contextmenu.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2023-05-01 21:34:00 +02:00
import 'package:adguard_home_manager/widgets/custom_list_tile.dart';
2023-05-06 04:16:24 +02:00
import 'package:adguard_home_manager/widgets/options_modal.dart';
2023-05-01 21:34:00 +02:00
2023-05-06 04:16:24 +02:00
import 'package:adguard_home_manager/models/menu_option.dart';
2023-05-04 22:38:37 +02:00
import 'package:adguard_home_manager/functions/copy_clipboard.dart';
2023-05-01 21:34:00 +02:00
import 'package:adguard_home_manager/models/clients.dart';
class ActiveClientTile extends StatelessWidget {
final AutoClient client;
final void Function(AutoClient) onTap;
final bool splitView;
final AutoClient? selectedClient;
const ActiveClientTile({
Key? key,
required this.client,
required this.onTap,
required this.splitView,
this.selectedClient
}) : super(key: key);
@override
Widget build(BuildContext context) {
2023-05-06 04:19:53 +02:00
void openOptionsModal() {
showDialog(
context: context,
builder: (context) => OptionsModal(
options: [
MenuOption(
title: AppLocalizations.of(context)!.copyClipboard,
icon: Icons.copy_rounded,
action: () {
copyToClipboard(
context: context,
value: client.name != ''
? client.name!
: client.ip,
successMessage: AppLocalizations.of(context)!.copiedClipboard,
);
},
)
]
),
);
}
2023-05-01 21:34:00 +02:00
if (splitView == true) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
2023-05-04 22:38:37 +02:00
child: ContextMenuArea(
builder: (context) => [
CustomListTile(
title: AppLocalizations.of(context)!.copyClipboard,
icon: Icons.copy_rounded,
onTap: () {
copyToClipboard(
context: context,
value: client.name != ''
? client.name!
: client.ip,
successMessage: AppLocalizations.of(context)!.copiedClipboard,
);
Navigator.pop(context);
},
)
],
child: Material(
color: Colors.transparent,
2023-05-01 21:34:00 +02:00
borderRadius: BorderRadius.circular(28),
2023-05-04 22:38:37 +02:00
child: InkWell(
borderRadius: BorderRadius.circular(28),
onTap: () => onTap(client),
2023-05-06 04:19:53 +02:00
onLongPress: () {
Navigator.pop(context);
openOptionsModal();
},
2023-05-04 22:38:37 +02:00
child: Container(
width: double.maxFinite,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(28),
color: client == selectedClient
? Theme.of(context).colorScheme.primaryContainer
: null
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
client.name != ''
? client.name!
: client.ip,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Theme.of(context).colorScheme.onSurface,
),
2023-05-01 21:34:00 +02:00
),
2023-05-04 22:38:37 +02:00
if (client.name != '') Text(client.ip)
],
),
)
],
),
2023-05-01 21:34:00 +02:00
),
2023-05-04 22:38:37 +02:00
Text(
client.source,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface
),
2023-05-01 21:34:00 +02:00
),
2023-05-04 22:38:37 +02:00
],
)
),
2023-05-01 21:34:00 +02:00
),
),
),
);
}
else {
2023-05-04 22:38:37 +02:00
return ContextMenuArea(
builder: (context) => [
CustomListTile(
title: AppLocalizations.of(context)!.copyClipboard,
icon: Icons.copy_rounded,
onTap: () {
copyToClipboard(
context: context,
value: client.name != ''
? client.name!
: client.ip,
successMessage: AppLocalizations.of(context)!.copiedClipboard,
);
Navigator.pop(context);
},
)
],
child: CustomListTile(
title: client.name != ''
? client.name!
: client.ip,
subtitle: client.name != ''
? client.ip
: null,
trailing: Text(
client.source,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface
),
2023-05-01 21:34:00 +02:00
),
2023-05-04 22:38:37 +02:00
onTap: () => onTap(client),
2023-05-06 04:19:53 +02:00
onLongPress: openOptionsModal,
2023-05-01 21:34:00 +02:00
),
);
}
}
}