mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 05:23:28 +01:00 
			
		
		
		
	Add regex filter to all select dialogs (#1110)
This commit is contained in:
		| @@ -598,6 +598,7 @@ class SelectionModal extends StatefulWidget { | |||||||
|  |  | ||||||
| class _SelectionModalState extends State<SelectionModal> { | class _SelectionModalState extends State<SelectionModal> { | ||||||
|   Map<MapEntry<String, List<String>>, bool> entrySelections = {}; |   Map<MapEntry<String, List<String>>, bool> entrySelections = {}; | ||||||
|  |   String filterRegex = ''; | ||||||
|   @override |   @override | ||||||
|   void initState() { |   void initState() { | ||||||
|     super.initState(); |     super.initState(); | ||||||
| @@ -618,11 +619,50 @@ class _SelectionModalState extends State<SelectionModal> { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|  |     Map<MapEntry<String, List<String>>, bool> filteredEntrySelections = {}; | ||||||
|  |     entrySelections.forEach((key, value) { | ||||||
|  |       var searchableText = key.value.isEmpty ? key.key : key.value[0]; | ||||||
|  |       if (filterRegex.isEmpty || RegExp(filterRegex).hasMatch(searchableText)) { | ||||||
|  |         filteredEntrySelections.putIfAbsent(key, () => value); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |     if (filterRegex.isNotEmpty && filteredEntrySelections.isEmpty) { | ||||||
|  |       entrySelections.forEach((key, value) { | ||||||
|  |         var searchableText = key.value.isEmpty ? key.key : key.value[0]; | ||||||
|  |         if (filterRegex.isEmpty || | ||||||
|  |             RegExp(filterRegex, caseSensitive: false) | ||||||
|  |                 .hasMatch(searchableText)) { | ||||||
|  |           filteredEntrySelections.putIfAbsent(key, () => value); | ||||||
|  |         } | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|     return AlertDialog( |     return AlertDialog( | ||||||
|       scrollable: true, |       scrollable: true, | ||||||
|       title: Text(widget.title ?? tr('pick')), |       title: Text(widget.title ?? tr('pick')), | ||||||
|       content: Column(children: [ |       content: Column(children: [ | ||||||
|         ...entrySelections.keys.map((entry) { |         GeneratedForm( | ||||||
|  |             items: [ | ||||||
|  |               [ | ||||||
|  |                 GeneratedFormTextField('filter', | ||||||
|  |                     label: tr('filter'), | ||||||
|  |                     required: false, | ||||||
|  |                     additionalValidators: [ | ||||||
|  |                       (value) { | ||||||
|  |                         return regExValidator(value); | ||||||
|  |                       } | ||||||
|  |                     ]) | ||||||
|  |               ] | ||||||
|  |             ], | ||||||
|  |             onValueChanges: (value, valid, isBuilding) { | ||||||
|  |               if (valid && !isBuilding) { | ||||||
|  |                 if (value['filter'] != null) { | ||||||
|  |                   setState(() { | ||||||
|  |                     filterRegex = value['filter']; | ||||||
|  |                   }); | ||||||
|  |                 } | ||||||
|  |               } | ||||||
|  |             }), | ||||||
|  |         ...filteredEntrySelections.keys.map((entry) { | ||||||
|           selectThis(bool? value) { |           selectThis(bool? value) { | ||||||
|             setState(() { |             setState(() { | ||||||
|               value ??= false; |               value ??= false; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user