adguard-home-manager/lib/screens/clients/client/blocked_services_section.dart

118 lines
4.4 KiB
Dart
Raw Normal View History

2023-10-07 23:03:30 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/screens/clients/client/client_screen_functions.dart';
class BlockedServicesSection extends StatelessWidget {
final bool useGlobalSettingsServices;
final List<String> blockedServices;
final void Function(List<String>) onUpdatedBlockedServices;
final void Function(bool) onUpdateServicesGlobalSettings;
const BlockedServicesSection({
2023-11-29 11:56:28 +01:00
super.key,
2023-10-07 23:03:30 +02:00
required this.useGlobalSettingsServices,
required this.blockedServices,
required this.onUpdatedBlockedServices,
required this.onUpdateServicesGlobalSettings
2023-11-29 11:56:28 +01:00
});
2023-10-07 23:03:30 +02:00
@override
Widget build(BuildContext context) {
return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
2023-10-07 23:03:30 +02:00
child: Material(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(28),
child: InkWell(
onTap: () => onUpdateServicesGlobalSettings(!useGlobalSettingsServices),
borderRadius: BorderRadius.circular(28),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 6
2023-10-07 23:03:30 +02:00
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2023-11-29 11:56:28 +01:00
Flexible(
child: Text(
AppLocalizations.of(context)!.useGlobalSettings,
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.onSurface
),
2023-10-07 23:03:30 +02:00
),
),
Switch(
value: useGlobalSettingsServices,
onChanged: (value) => onUpdateServicesGlobalSettings(value),
)
],
),
),
),
),
),
const SizedBox(height: 12),
2023-10-07 23:03:30 +02:00
Material(
color: Colors.transparent,
child: InkWell(
onTap: useGlobalSettingsServices == false
? () => openServicesModal(
context: context,
blockedServices: blockedServices,
onUpdateBlockedServices: onUpdatedBlockedServices
)
: null,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 32
2023-10-07 23:03:30 +02:00
),
child: Row(
children: [
Icon(
Icons.public,
color: useGlobalSettingsServices == false
? Theme.of(context).listTileTheme.iconColor
: Theme.of(context).colorScheme.onSurface.withOpacity(0.38),
),
const SizedBox(width: 16),
2023-11-29 11:56:28 +01:00
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2023-10-07 23:03:30 +02:00
Text(
2023-11-29 11:56:28 +01:00
AppLocalizations.of(context)!.selectBlockedServices,
2023-10-07 23:03:30 +02:00
style: TextStyle(
2023-11-29 11:56:28 +01:00
fontSize: 16,
color: useGlobalSettingsServices == false
? Theme.of(context).colorScheme.onSurface
: Theme.of(context).colorScheme.onSurface.withOpacity(0.38),
2023-10-07 23:03:30 +02:00
),
2023-11-29 11:56:28 +01:00
),
if (useGlobalSettingsServices == false) ...[
const SizedBox(height: 5),
Text(
blockedServices.isNotEmpty
? "${blockedServices.length} ${AppLocalizations.of(context)!.servicesBlocked}"
: AppLocalizations.of(context)!.noBlockedServicesSelected,
style: TextStyle(
color: Theme.of(context).listTileTheme.iconColor
),
)
]
],
),
2023-10-07 23:03:30 +02:00
)
],
),
),
),
),
],
);
}
}