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

114 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/constants/services.dart';
class ServicesModal extends StatefulWidget {
final List<String> blockedServices;
final void Function(List<String>) onConfirm;
const ServicesModal({
Key? key,
required this.blockedServices,
required this.onConfirm,
}) : super(key: key);
@override
State<ServicesModal> createState() => _ServicesModalState();
}
class _ServicesModalState extends State<ServicesModal> {
List<String> blockedServices = [];
@override
void initState() {
blockedServices = widget.blockedServices;
super.initState();
}
void checkUncheckService(bool value, String service) {
if (value == true) {
setState(() {
blockedServices.add(service);
});
}
else if (value == false) {
setState(() {
blockedServices = blockedServices.where((s) => s != service).toList();
});
}
}
@override
Widget build(BuildContext context) {
return AlertDialog(
scrollable: true,
contentPadding: const EdgeInsets.symmetric(
horizontal: 0,
2022-11-04 17:04:25 +01:00
vertical: 16
),
title: Column(
children: [
2022-11-04 17:04:25 +01:00
Icon(
Icons.public,
2022-11-05 02:35:35 +01:00
color: Theme.of(context).listTileTheme.iconColor
2022-11-04 17:04:25 +01:00
),
const SizedBox(height: 16),
Text(
AppLocalizations.of(context)!.services,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
),
)
],
),
content: SizedBox(
width: double.minPositive,
height: MediaQuery.of(context).size.height*0.5,
child: ListView.builder(
shrinkWrap: true,
itemCount: services.length,
itemBuilder: (context, index) => CheckboxListTile(
title: Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
2022-10-07 00:47:17 +02:00
services[index]['label']!,
2022-11-04 17:04:25 +01:00
style: TextStyle(
fontWeight: FontWeight.normal,
color: Theme.of(context).colorScheme.onSurface
),
),
),
2022-10-07 00:47:17 +02:00
value: blockedServices.contains(services[index]['id']),
checkboxShape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)
),
2022-10-07 00:47:17 +02:00
onChanged: (value) => checkUncheckService(value!, services[index]['id']!)
)
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(AppLocalizations.of(context)!.cancel)
),
TextButton(
onPressed: blockedServices.isNotEmpty
? () {
widget.onConfirm(blockedServices);
Navigator.pop(context);
}
: null,
child: Text(
AppLocalizations.of(context)!.confirm,
style: TextStyle(
color: blockedServices.isNotEmpty
2023-01-25 20:51:23 +01:00
? Theme.of(context).colorScheme.primary
2022-11-04 17:04:25 +01:00
: Theme.of(context).colorScheme.onSurface.withOpacity(0.38)
),
)
),
],
);
}
}