Skip to content

Commit

Permalink
Merge pull request rustdesk#6195 from fufesou/fix/autocomplete
Browse files Browse the repository at this point in the history
fix, autocomplete, fill id field
  • Loading branch information
rustdesk authored Oct 27, 2023
2 parents 8a2bd1c + e32748d commit 625f2d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
11 changes: 3 additions & 8 deletions flutter/lib/common/widgets/autocomplete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ import 'package:flutter_hbb/common/widgets/peer_card.dart';
}

class AutocompletePeerTile extends StatefulWidget {
final IDTextEditingController idController;
final VoidCallback onSelect;
final Peer peer;

const AutocompletePeerTile({
Key? key,
required this.idController,
required this.onSelect,
required this.peer,
}) : super(key: key);

Expand All @@ -85,12 +85,7 @@ class _AutocompletePeerTileState extends State<AutocompletePeerTile>{
fontSize: 11,
color: Theme.of(context).textTheme.titleLarge?.color?.withOpacity(0.6));
final child = GestureDetector(
onTap: () {
setState(() {
widget.idController.id = widget.peer.id;
FocusScope.of(context).unfocus();
});
},
onTap: () => widget.onSelect(),
child:
Container(
height: 42,
Expand Down
8 changes: 7 additions & 1 deletion flutter/lib/desktop/pages/connection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ class _ConnectionPageState extends State<ConnectionPage>
},
));
},
onSelected: (option) {
setState(() {
_idController.id = option.id;
FocusScope.of(context).unfocus();
});
},
optionsViewBuilder: (BuildContext context, AutocompleteOnSelected<Peer> onSelected, Iterable<Peer> options) {
double maxHeight = options.length * 50;
maxHeight = maxHeight > 200 ? 200 : maxHeight;
Expand Down Expand Up @@ -304,7 +310,7 @@ class _ConnectionPageState extends State<ConnectionPage>
: Padding(
padding: const EdgeInsets.only(top: 5),
child: ListView(
children: options.map((peer) => AutocompletePeerTile(idController: _idController, peer: peer)).toList(),
children: options.map((peer) => AutocompletePeerTile(onSelect: () => onSelected(peer), peer: peer)).toList(),
),
),
),
Expand Down
8 changes: 7 additions & 1 deletion flutter/lib/mobile/pages/connection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ class _ConnectionPageState extends State<ConnectionPage> {
inputFormatters: [IDTextInputFormatter()],
);
},
onSelected: (option) {
setState(() {
_idController.id = option.id;
FocusScope.of(context).unfocus();
});
},
optionsViewBuilder: (BuildContext context, AutocompleteOnSelected<Peer> onSelected, Iterable<Peer> options) {
double maxHeight = options.length * 50;
maxHeight = maxHeight > 200 ? 200 : maxHeight;
Expand All @@ -268,7 +274,7 @@ class _ConnectionPageState extends State<ConnectionPage> {
)))
: ListView(
padding: EdgeInsets.only(top: 5),
children: options.map((peer) => AutocompletePeerTile(idController: _idController, peer: peer)).toList(),
children: options.map((peer) => AutocompletePeerTile(onSelect: () => onSelected(peer), peer: peer)).toList(),
))))
);
},
Expand Down

0 comments on commit 625f2d2

Please sign in to comment.