Skip to content

Commit

Permalink
better auto complete
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Aug 20, 2024
1 parent ba7399d commit ea14a61
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lib/features/settings/widgets/settings_input_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,47 @@ class SettingsInputDialog<T> extends HookConsumerWidget with PresLogger {
mainAxisSize: MainAxisSize.min,
children: [
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
CustomTextFormField(
controller: textController,
Expand Down
40 changes: 40 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,14 @@ packages:
url: "https://pub.dev"
source: hosted
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:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -1188,6 +1196,38 @@ packages:
url: "https://pub.dev"
source: hosted
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:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ dependencies:
protobuf: ^3.1.0
grpc: ^3.2.4
dynamic_color: ^1.7.0
flutter_typeahead: ^5.0.1
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down

0 comments on commit ea14a61

Please sign in to comment.