From 459d316cf3519277e31ab370a659c958910cb2f7 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Thu, 6 Oct 2022 23:19:51 +0200 Subject: [PATCH] Added tags selection modal --- lib/screens/clients/add_client_modal.dart | 25 ++++++- lib/screens/clients/tags_modal.dart | 87 +++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 lib/screens/clients/tags_modal.dart diff --git a/lib/screens/clients/add_client_modal.dart b/lib/screens/clients/add_client_modal.dart index bb6ba25..3eb16f6 100644 --- a/lib/screens/clients/add_client_modal.dart +++ b/lib/screens/clients/add_client_modal.dart @@ -1,7 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import 'package:uuid/uuid.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:adguard_home_manager/screens/clients/tags_modal.dart'; + +import 'package:adguard_home_manager/providers/servers_provider.dart'; import 'package:adguard_home_manager/models/add_client.dart'; class AddClientModal extends StatefulWidget { @@ -21,6 +25,8 @@ class _AddClientModalState extends State { TextEditingController nameController = TextEditingController(); + String? selectedTag; + List> identifiersControllers = [ { 'id': 0, @@ -50,6 +56,8 @@ class _AddClientModalState extends State { @override Widget build(BuildContext context) { + final serversProvider = Provider.of(context); + void createClient() { } @@ -94,6 +102,17 @@ class _AddClientModalState extends State { } } + void openTagsModal() { + showDialog( + context: context, + builder: (context) => TagsModal( + selectedTag: selectedTag, + tags: serversProvider.clients.data!.supportedTags, + onConfirm: (selected) => setState(() => selectedTag = selected), + ) + ); + } + Widget settignsTile({ required String label, required bool? value, @@ -192,7 +211,7 @@ class _AddClientModalState extends State { Material( color: Colors.transparent, child: InkWell( - onTap: () => {}, + onTap: openTagsModal, child: Padding( padding: const EdgeInsets.symmetric( vertical: 10, horizontal: 20 @@ -215,7 +234,9 @@ class _AddClientModalState extends State { ), const SizedBox(height: 5), Text( - AppLocalizations.of(context)!.noTagsSelected, + selectedTag != null + ? selectedTag! + : AppLocalizations.of(context)!.noTagsSelected, style: const TextStyle( color: Colors.grey ), diff --git a/lib/screens/clients/tags_modal.dart b/lib/screens/clients/tags_modal.dart new file mode 100644 index 0000000..d7b05e4 --- /dev/null +++ b/lib/screens/clients/tags_modal.dart @@ -0,0 +1,87 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +class TagsModal extends StatefulWidget { + final String? selectedTag; + final List tags; + final void Function(String) onConfirm; + + const TagsModal({ + Key? key, + this.selectedTag, + required this.tags, + required this.onConfirm, + }) : super(key: key); + + @override + State createState() => _TagsModalState(); +} + +class _TagsModalState extends State { + String? selectedTag; + + @override + void initState() { + selectedTag = widget.selectedTag; + super.initState(); + } + + @override + Widget build(BuildContext context) { + return AlertDialog( + scrollable: true, + contentPadding: const EdgeInsets.symmetric( + horizontal: 0, + vertical: 20 + ), + title: Column( + children: [ + const Icon(Icons.label_rounded), + const SizedBox(height: 20), + Text(AppLocalizations.of(context)!.tags) + ], + ), + content: SizedBox( + width: double.minPositive, + height: MediaQuery.of(context).size.height*0.5, + child: ListView.builder( + shrinkWrap: true, + itemCount: widget.tags.length, + itemBuilder: (context, index) => RadioListTile( + title: Text( + widget.tags[index], + style: const TextStyle( + fontWeight: FontWeight.normal + ), + ), + value: widget.tags[index], + groupValue: selectedTag, + onChanged: (value) => setState(() => selectedTag = value) + ) + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: Text(AppLocalizations.of(context)!.cancel) + ), + TextButton( + onPressed: selectedTag != null + ? () { + widget.onConfirm(selectedTag!); + Navigator.pop(context); + } + : null, + child: Text( + AppLocalizations.of(context)!.confirm, + style: TextStyle( + color: selectedTag != null + ? Theme.of(context).primaryColor + : Colors.grey + ), + ) + ), + ], + ); + } +} \ No newline at end of file