fix: mobile autocomplete options (#10060)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-11-26 16:24:51 +08:00 committed by GitHub
parent 8a70932cd6
commit 458a88fb89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,6 +48,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
bool isPeersLoaded = false;
StreamSubscription? _uniLinksSubscription;
// https://github.com/flutter/flutter/issues/157244
Iterable<Peer> _autocompleteOpts = [];
_ConnectionPageState() {
if (!isWeb) _uniLinksSubscription = listenUniLinks();
_idController.addListener(() {
@ -166,7 +169,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
child: Autocomplete<Peer>(
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return const Iterable<Peer>.empty();
_autocompleteOpts = const Iterable<Peer>.empty();
} else if (peers.isEmpty && !isPeersLoaded) {
Peer emptyPeer = Peer(
id: '',
@ -182,7 +185,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
rdpUsername: '',
loginName: '',
);
return [emptyPeer];
_autocompleteOpts = [emptyPeer];
} else {
String textWithoutSpaces =
textEditingValue.text.replaceAll(" ", "");
@ -194,7 +197,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
}
String textToFind = textEditingValue.text.toLowerCase();
return peers
_autocompleteOpts = peers
.where((peer) =>
peer.id.toLowerCase().contains(textToFind) ||
peer.username
@ -206,6 +209,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
peer.alias.toLowerCase().contains(textToFind))
.toList();
}
return _autocompleteOpts;
},
fieldViewBuilder: (BuildContext context,
TextEditingController fieldTextEditingController,
@ -274,6 +278,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
optionsViewBuilder: (BuildContext context,
AutocompleteOnSelected<Peer> onSelected,
Iterable<Peer> options) {
options = _autocompleteOpts;
double maxHeight = options.length * 50;
if (options.length == 1) {
maxHeight = 52;