autocomplete suggestion on tap
This commit is contained in:
@@ -17,7 +17,10 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:nullability/nullability.dart';
|
import 'package:nullability/nullability.dart';
|
||||||
@@ -38,7 +41,6 @@ class SearchField extends HookConsumerWidget {
|
|||||||
final bool showSuggestions;
|
final bool showSuggestions;
|
||||||
final int? maxLines;
|
final int? maxLines;
|
||||||
final int? minLines;
|
final int? minLines;
|
||||||
final VoidCallback? onTap;
|
|
||||||
final bool unfocusOnTapOutside;
|
final bool unfocusOnTapOutside;
|
||||||
final GlobalKey? textFieldKey;
|
final GlobalKey? textFieldKey;
|
||||||
|
|
||||||
@@ -55,7 +57,6 @@ class SearchField extends HookConsumerWidget {
|
|||||||
this.focusNode,
|
this.focusNode,
|
||||||
this.maxLines = 1,
|
this.maxLines = 1,
|
||||||
this.minLines = 1,
|
this.minLines = 1,
|
||||||
this.onTap,
|
|
||||||
this.unfocusOnTapOutside = true,
|
this.unfocusOnTapOutside = true,
|
||||||
this.showBangIcon = true,
|
this.showBangIcon = true,
|
||||||
this.autofocus = false,
|
this.autofocus = false,
|
||||||
@@ -152,7 +153,18 @@ class SearchField extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
onSubmitted: onSubmitted,
|
onSubmitted: onSubmitted,
|
||||||
onTap: onTap,
|
onTap: () {
|
||||||
|
if (suggestion.value != null) {
|
||||||
|
unawaited(HapticFeedback.lightImpact());
|
||||||
|
|
||||||
|
textEditingController.text = suggestion.value!;
|
||||||
|
textEditingController.selection = TextSelection.collapsed(
|
||||||
|
offset: suggestion.value!.length,
|
||||||
|
);
|
||||||
|
|
||||||
|
suggestion.value = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user