fix: mobile autocomplete options (#10060)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
8a70932cd6
commit
458a88fb89
@ -48,6 +48,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
bool isPeersLoaded = false;
|
bool isPeersLoaded = false;
|
||||||
StreamSubscription? _uniLinksSubscription;
|
StreamSubscription? _uniLinksSubscription;
|
||||||
|
|
||||||
|
// https://github.com/flutter/flutter/issues/157244
|
||||||
|
Iterable<Peer> _autocompleteOpts = [];
|
||||||
|
|
||||||
_ConnectionPageState() {
|
_ConnectionPageState() {
|
||||||
if (!isWeb) _uniLinksSubscription = listenUniLinks();
|
if (!isWeb) _uniLinksSubscription = listenUniLinks();
|
||||||
_idController.addListener(() {
|
_idController.addListener(() {
|
||||||
@ -166,7 +169,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
child: Autocomplete<Peer>(
|
child: Autocomplete<Peer>(
|
||||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||||
if (textEditingValue.text == '') {
|
if (textEditingValue.text == '') {
|
||||||
return const Iterable<Peer>.empty();
|
_autocompleteOpts = const Iterable<Peer>.empty();
|
||||||
} else if (peers.isEmpty && !isPeersLoaded) {
|
} else if (peers.isEmpty && !isPeersLoaded) {
|
||||||
Peer emptyPeer = Peer(
|
Peer emptyPeer = Peer(
|
||||||
id: '',
|
id: '',
|
||||||
@ -182,7 +185,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
rdpUsername: '',
|
rdpUsername: '',
|
||||||
loginName: '',
|
loginName: '',
|
||||||
);
|
);
|
||||||
return [emptyPeer];
|
_autocompleteOpts = [emptyPeer];
|
||||||
} else {
|
} else {
|
||||||
String textWithoutSpaces =
|
String textWithoutSpaces =
|
||||||
textEditingValue.text.replaceAll(" ", "");
|
textEditingValue.text.replaceAll(" ", "");
|
||||||
@ -194,7 +197,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
}
|
}
|
||||||
String textToFind = textEditingValue.text.toLowerCase();
|
String textToFind = textEditingValue.text.toLowerCase();
|
||||||
|
|
||||||
return peers
|
_autocompleteOpts = peers
|
||||||
.where((peer) =>
|
.where((peer) =>
|
||||||
peer.id.toLowerCase().contains(textToFind) ||
|
peer.id.toLowerCase().contains(textToFind) ||
|
||||||
peer.username
|
peer.username
|
||||||
@ -206,6 +209,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
peer.alias.toLowerCase().contains(textToFind))
|
peer.alias.toLowerCase().contains(textToFind))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
return _autocompleteOpts;
|
||||||
},
|
},
|
||||||
fieldViewBuilder: (BuildContext context,
|
fieldViewBuilder: (BuildContext context,
|
||||||
TextEditingController fieldTextEditingController,
|
TextEditingController fieldTextEditingController,
|
||||||
@ -274,6 +278,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
|||||||
optionsViewBuilder: (BuildContext context,
|
optionsViewBuilder: (BuildContext context,
|
||||||
AutocompleteOnSelected<Peer> onSelected,
|
AutocompleteOnSelected<Peer> onSelected,
|
||||||
Iterable<Peer> options) {
|
Iterable<Peer> options) {
|
||||||
|
options = _autocompleteOpts;
|
||||||
double maxHeight = options.length * 50;
|
double maxHeight = options.length * 50;
|
||||||
if (options.length == 1) {
|
if (options.length == 1) {
|
||||||
maxHeight = 52;
|
maxHeight = 52;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user