mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-01 05:10:15 +02:00
Added autocomplete for F-Droid repos (#1681)
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:obtainium/components/generated_form_modal.dart';
|
||||
import 'package:obtainium/providers/source_provider.dart';
|
||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||
|
||||
abstract class GeneratedFormItem {
|
||||
late String key;
|
||||
@@ -276,39 +277,62 @@ class _GeneratedFormState extends State<GeneratedForm> {
|
||||
var formItem = e.value;
|
||||
if (formItem is GeneratedFormTextField) {
|
||||
final formFieldKey = GlobalKey<FormFieldState>();
|
||||
return TextFormField(
|
||||
keyboardType: formItem.textInputType,
|
||||
obscureText: formItem.password,
|
||||
autocorrect: !formItem.password,
|
||||
enableSuggestions: !formItem.password,
|
||||
key: formFieldKey,
|
||||
initialValue: values[formItem.key],
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
autofillHints: formItem.autoCompleteOptions,
|
||||
onChanged: (value) {
|
||||
var ctrl = TextEditingController(text: values[formItem.key]);
|
||||
return TypeAheadField<String>(
|
||||
controller: ctrl,
|
||||
builder: (context, controller, focusNode) {
|
||||
return TextFormField(
|
||||
controller: ctrl,
|
||||
focusNode: focusNode,
|
||||
keyboardType: formItem.textInputType,
|
||||
obscureText: formItem.password,
|
||||
autocorrect: !formItem.password,
|
||||
enableSuggestions: !formItem.password,
|
||||
key: formFieldKey,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
values[formItem.key] = value;
|
||||
someValueChanged();
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
helperText:
|
||||
formItem.label + (formItem.required ? ' *' : ''),
|
||||
hintText: formItem.hint),
|
||||
minLines: formItem.max <= 1 ? null : formItem.max,
|
||||
maxLines: formItem.max <= 1 ? 1 : formItem.max,
|
||||
validator: (value) {
|
||||
if (formItem.required &&
|
||||
(value == null || value.trim().isEmpty)) {
|
||||
return '${formItem.label} ${tr('requiredInBrackets')}';
|
||||
}
|
||||
for (var validator in formItem.additionalValidators) {
|
||||
String? result = validator(value);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
},
|
||||
itemBuilder: (context, value) {
|
||||
return ListTile(title: Text(value));
|
||||
},
|
||||
onSelected: (value) {
|
||||
ctrl.text = value;
|
||||
setState(() {
|
||||
values[formItem.key] = value;
|
||||
someValueChanged();
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
helperText: formItem.label + (formItem.required ? ' *' : ''),
|
||||
hintText: formItem.hint),
|
||||
minLines: formItem.max <= 1 ? null : formItem.max,
|
||||
maxLines: formItem.max <= 1 ? 1 : formItem.max,
|
||||
validator: (value) {
|
||||
if (formItem.required &&
|
||||
(value == null || value.trim().isEmpty)) {
|
||||
return '${formItem.label} ${tr('requiredInBrackets')}';
|
||||
}
|
||||
for (var validator in formItem.additionalValidators) {
|
||||
String? result = validator(value);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
suggestionsCallback: (search) {
|
||||
return formItem.autoCompleteOptions
|
||||
?.where((t) => t.toLowerCase().contains(search.toLowerCase()))
|
||||
.toList();
|
||||
},
|
||||
hideOnEmpty: true,
|
||||
);
|
||||
} else if (formItem is GeneratedFormDropdown) {
|
||||
if (formItem.opts!.isEmpty) {
|
||||
|
@@ -312,7 +312,10 @@ class AddAppPageState extends State<AddAppPage> {
|
||||
a.app.overrideSource)
|
||||
.runtimeType ==
|
||||
e.runtimeType)
|
||||
.map((a) => Uri.parse(a.app.url).host)
|
||||
.map((a) {
|
||||
var uri = Uri.parse(a.app.url);
|
||||
return '${uri.origin}${uri.path}';
|
||||
})
|
||||
],
|
||||
defaultValue:
|
||||
e.hosts.isNotEmpty ? e.hosts[0] : '',
|
||||
|
Reference in New Issue
Block a user