better auto complete

This commit is contained in:
Hiddify
2024-08-20 13:18:26 -04:00
parent ba7399dde4
commit ea14a619cc
3 changed files with 82 additions and 1 deletions

View File

@@ -48,7 +48,47 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
if (possibleValues != null) if (possibleValues != null)
AutocompleteField(initialValue: initialValue.toString(), options: possibleValues!.map((e) => e.toString()).toList()) // AutocompleteField(initialValue: initialValue.toString(), options: possibleValues!.map((e) => e.toString()).toList())
TypeAheadField<String>(
controller: textController,
builder: (context, controller, focusNode) {
return TextField(
controller: controller,
focusNode: focusNode,
textDirection: TextDirection.ltr,
autofocus: true,
// decoration: InputDecoration(
// // border: OutlineInputBorder(),
// // labelText: 'City',
// )
);
},
// Callback to fetch suggestions based on user input
suggestionsCallback: (pattern) async {
final items = possibleValues!.map((p) => p.toString());
var res = items.where((suggestion) => suggestion.toLowerCase().contains(pattern.toLowerCase())).toList();
if (res.length <= 1) res = [pattern, ...items.where((s) => s != pattern)];
return res;
},
// Widget to build each suggestion in the list
itemBuilder: (context, suggestion) {
return ListTile(
contentPadding: const EdgeInsets.symmetric(vertical: 3, horizontal: 10), // Minimize ListTile padding
minTileHeight: 0,
title: Text(
suggestion,
textDirection: TextDirection.ltr,
style: Theme.of(context).textTheme.bodySmall,
),
);
},
// Callback when a suggestion is selected
onSelected: (suggestion) {
// Handle the selected suggestion
print('Selected: $suggestion');
textController.text = suggestion.toString();
},
)
else else
CustomTextFormField( CustomTextFormField(
controller: textController, controller: textController,

View File

@@ -630,6 +630,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.8" version: "1.0.8"
flutter_typeahead:
dependency: "direct main"
description:
name: flutter_typeahead
sha256: d64712c65db240b1057559b952398ebb6e498077baeebf9b0731dade62438a6d
url: "https://pub.dev"
source: hosted
version: "5.2.0"
flutter_web_plugins: flutter_web_plugins:
dependency: transitive dependency: transitive
description: flutter description: flutter
@@ -1188,6 +1196,38 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.8" version: "2.1.8"
pointer_interceptor:
dependency: transitive
description:
name: pointer_interceptor
sha256: "57210410680379aea8b1b7ed6ae0c3ad349bfd56fe845b8ea934a53344b9d523"
url: "https://pub.dev"
source: hosted
version: "0.10.1+2"
pointer_interceptor_ios:
dependency: transitive
description:
name: pointer_interceptor_ios
sha256: a6906772b3205b42c44614fcea28f818b1e5fdad73a4ca742a7bd49818d9c917
url: "https://pub.dev"
source: hosted
version: "0.10.1"
pointer_interceptor_platform_interface:
dependency: transitive
description:
name: pointer_interceptor_platform_interface
sha256: "0597b0560e14354baeb23f8375cd612e8bd4841bf8306ecb71fcd0bb78552506"
url: "https://pub.dev"
source: hosted
version: "0.10.0+1"
pointer_interceptor_web:
dependency: transitive
description:
name: pointer_interceptor_web
sha256: "7a7087782110f8c1827170660b09f8aa893e0e9a61431dbbe2ac3fc482e8c044"
url: "https://pub.dev"
source: hosted
version: "0.10.2+1"
pool: pool:
dependency: transitive dependency: transitive
description: description:

View File

@@ -95,6 +95,7 @@ dependencies:
protobuf: ^3.1.0 protobuf: ^3.1.0
grpc: ^3.2.4 grpc: ^3.2.4
dynamic_color: ^1.7.0 dynamic_color: ^1.7.0
flutter_typeahead: ^5.0.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter