From 0eed72a60d7a93bfcf9f1426c7fad33fcf755a30 Mon Sep 17 00:00:00 2001 From: Kingtous Date: Tue, 23 Aug 2022 17:52:53 +0800 Subject: [PATCH] feat: find ID Signed-off-by: Kingtous --- .../lib/desktop/pages/connection_page.dart | 35 +++++++++++++++++-- flutter/lib/desktop/widgets/peer_widget.dart | 35 +++++++++++++------ 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index 4e2a5639f..08f334c4d 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -977,6 +977,9 @@ class _PeerTabbedPageState extends State<_PeerTabbedPage> // hard code for now void _handleTabSelection() { if (_tabController.indexIsChanging) { + // reset search text + peerSearchText.value = ""; + peerSearchTextController.clear(); _tabIndex.value = _tabController.index; switch (_tabController.index) { case 0: @@ -1063,7 +1066,31 @@ class _PeerTabbedPageState extends State<_PeerTabbedPage> } _createSearchBar(BuildContext context) { - return Offstage(); + return Container( + width: 175, + height: 30, + margin: EdgeInsets.only(right: 16), + decoration: BoxDecoration(color: Colors.white), + child: Obx( + () => TextField( + controller: peerSearchTextController, + onChanged: (searchText) { + peerSearchText.value = searchText; + }, + decoration: InputDecoration( + prefixIcon: Icon( + Icons.search, + size: 20, + ), + contentPadding: EdgeInsets.zero, + hintText: translate("Search ID"), + hintStyle: TextStyle(fontSize: 14), + border: OutlineInputBorder(), + isDense: true, + ), + ), + ), + ); } _createPeerViewTypeSwitch(BuildContext context) { @@ -1082,6 +1109,7 @@ class _PeerTabbedPageState extends State<_PeerTabbedPage> child: Icon( Icons.grid_view_rounded, size: 20, + color: Colors.black54, )), ), ), @@ -1096,11 +1124,12 @@ class _PeerTabbedPageState extends State<_PeerTabbedPage> }, child: Icon( Icons.list, - size: 20, + size: 24, + color: Colors.black54, )), ), ), ], - ); + ).paddingOnly(right: 16.0); } } diff --git a/flutter/lib/desktop/widgets/peer_widget.dart b/flutter/lib/desktop/widgets/peer_widget.dart index 9014cb608..70df44ab5 100644 --- a/flutter/lib/desktop/widgets/peer_widget.dart +++ b/flutter/lib/desktop/widgets/peer_widget.dart @@ -15,10 +15,16 @@ import 'peercard_widget.dart'; typedef OffstageFunc = bool Function(Peer peer); typedef PeerCardWidgetFunc = Widget Function(Peer peer); +/// for peer search text, global obs value +final peerSearchText = "".obs; +final peerSearchTextController = + TextEditingController(text: peerSearchText.value); + class _PeerWidget extends StatefulWidget { late final _peers; late final OffstageFunc _offstageFunc; late final PeerCardWidgetFunc _peerCardWidgetFunc; + _PeerWidget(Peers peers, OffstageFunc offstageFunc, PeerCardWidgetFunc peerCardWidgetFunc, {Key? key}) @@ -72,15 +78,24 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener { @override Widget build(BuildContext context) { - final space = 8.0; + final space = 12.0; return ChangeNotifierProvider( create: (context) => super.widget._peers, - child: SingleChildScrollView( - child: Consumer( - builder: (context, peers, child) => Wrap( - children: () { + child: Consumer( + builder: (context, peers, child) => peers.peers.isEmpty + ? Center( + child: Text(translate("Empty")), + ) + : SingleChildScrollView( + child: ObxValue((searchText) { final cards = []; - peers.peers.forEach((peer) { + peers.peers.where((peer) { + if (searchText.isEmpty) { + return true; + } else { + return peer.id.contains(peerSearchText.value); + } + }).forEach((peer) { cards.add(Offstage( offstage: super.widget._offstageFunc(peer), child: Obx( @@ -105,10 +120,10 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener { ), ))); }); - return cards; - }(), - spacing: space, - runSpacing: space))), + return Wrap( + children: cards, spacing: space, runSpacing: space); + }, peerSearchText), + )), ); }