From e32748daf2176451f2daa7ed45d6b35aa5ce44b6 Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 27 Oct 2023 17:00:13 +0800 Subject: [PATCH] fix, autocomplete, fill id field Signed-off-by: fufesou --- flutter/lib/common/widgets/autocomplete.dart | 11 +++-------- flutter/lib/desktop/pages/connection_page.dart | 8 +++++++- flutter/lib/mobile/pages/connection_page.dart | 8 +++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/flutter/lib/common/widgets/autocomplete.dart b/flutter/lib/common/widgets/autocomplete.dart index 9c14eab7f..b40c4ef82 100644 --- a/flutter/lib/common/widgets/autocomplete.dart +++ b/flutter/lib/common/widgets/autocomplete.dart @@ -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); @@ -85,12 +85,7 @@ class _AutocompletePeerTileState extends State{ 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, diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index a40e8abe0..bf923d388 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -277,6 +277,12 @@ class _ConnectionPageState extends State }, )); }, + onSelected: (option) { + setState(() { + _idController.id = option.id; + FocusScope.of(context).unfocus(); + }); + }, optionsViewBuilder: (BuildContext context, AutocompleteOnSelected onSelected, Iterable options) { double maxHeight = options.length * 50; maxHeight = maxHeight > 200 ? 200 : maxHeight; @@ -304,7 +310,7 @@ class _ConnectionPageState extends State : 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(), ), ), ), diff --git a/flutter/lib/mobile/pages/connection_page.dart b/flutter/lib/mobile/pages/connection_page.dart index 1c1dec8fc..a4e3c7f4d 100644 --- a/flutter/lib/mobile/pages/connection_page.dart +++ b/flutter/lib/mobile/pages/connection_page.dart @@ -245,6 +245,12 @@ class _ConnectionPageState extends State { inputFormatters: [IDTextInputFormatter()], ); }, + onSelected: (option) { + setState(() { + _idController.id = option.id; + FocusScope.of(context).unfocus(); + }); + }, optionsViewBuilder: (BuildContext context, AutocompleteOnSelected onSelected, Iterable options) { double maxHeight = options.length * 50; maxHeight = maxHeight > 200 ? 200 : maxHeight; @@ -268,7 +274,7 @@ class _ConnectionPageState extends State { ))) : 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(), )))) ); },