feat: find ID
Signed-off-by: Kingtous <kingtous@qq.com>
This commit is contained in:
parent
4f859d3c9d
commit
0eed72a60d
@ -977,6 +977,9 @@ class _PeerTabbedPageState extends State<_PeerTabbedPage>
|
|||||||
// hard code for now
|
// hard code for now
|
||||||
void _handleTabSelection() {
|
void _handleTabSelection() {
|
||||||
if (_tabController.indexIsChanging) {
|
if (_tabController.indexIsChanging) {
|
||||||
|
// reset search text
|
||||||
|
peerSearchText.value = "";
|
||||||
|
peerSearchTextController.clear();
|
||||||
_tabIndex.value = _tabController.index;
|
_tabIndex.value = _tabController.index;
|
||||||
switch (_tabController.index) {
|
switch (_tabController.index) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -1063,7 +1066,31 @@ class _PeerTabbedPageState extends State<_PeerTabbedPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
_createSearchBar(BuildContext context) {
|
_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) {
|
_createPeerViewTypeSwitch(BuildContext context) {
|
||||||
@ -1082,6 +1109,7 @@ class _PeerTabbedPageState extends State<_PeerTabbedPage>
|
|||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.grid_view_rounded,
|
Icons.grid_view_rounded,
|
||||||
size: 20,
|
size: 20,
|
||||||
|
color: Colors.black54,
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -1096,11 +1124,12 @@ class _PeerTabbedPageState extends State<_PeerTabbedPage>
|
|||||||
},
|
},
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.list,
|
Icons.list,
|
||||||
size: 20,
|
size: 24,
|
||||||
|
color: Colors.black54,
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
).paddingOnly(right: 16.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,16 @@ import 'peercard_widget.dart';
|
|||||||
typedef OffstageFunc = bool Function(Peer peer);
|
typedef OffstageFunc = bool Function(Peer peer);
|
||||||
typedef PeerCardWidgetFunc = Widget 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 {
|
class _PeerWidget extends StatefulWidget {
|
||||||
late final _peers;
|
late final _peers;
|
||||||
late final OffstageFunc _offstageFunc;
|
late final OffstageFunc _offstageFunc;
|
||||||
late final PeerCardWidgetFunc _peerCardWidgetFunc;
|
late final PeerCardWidgetFunc _peerCardWidgetFunc;
|
||||||
|
|
||||||
_PeerWidget(Peers peers, OffstageFunc offstageFunc,
|
_PeerWidget(Peers peers, OffstageFunc offstageFunc,
|
||||||
PeerCardWidgetFunc peerCardWidgetFunc,
|
PeerCardWidgetFunc peerCardWidgetFunc,
|
||||||
{Key? key})
|
{Key? key})
|
||||||
@ -72,15 +78,24 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final space = 8.0;
|
final space = 12.0;
|
||||||
return ChangeNotifierProvider<Peers>(
|
return ChangeNotifierProvider<Peers>(
|
||||||
create: (context) => super.widget._peers,
|
create: (context) => super.widget._peers,
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Consumer<Peers>(
|
child: Consumer<Peers>(
|
||||||
builder: (context, peers, child) => Wrap(
|
builder: (context, peers, child) => peers.peers.isEmpty
|
||||||
children: () {
|
? Center(
|
||||||
|
child: Text(translate("Empty")),
|
||||||
|
)
|
||||||
|
: SingleChildScrollView(
|
||||||
|
child: ObxValue<RxString>((searchText) {
|
||||||
final cards = <Widget>[];
|
final cards = <Widget>[];
|
||||||
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(
|
cards.add(Offstage(
|
||||||
offstage: super.widget._offstageFunc(peer),
|
offstage: super.widget._offstageFunc(peer),
|
||||||
child: Obx(
|
child: Obx(
|
||||||
@ -105,10 +120,10 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
|
|||||||
),
|
),
|
||||||
)));
|
)));
|
||||||
});
|
});
|
||||||
return cards;
|
return Wrap(
|
||||||
}(),
|
children: cards, spacing: space, runSpacing: space);
|
||||||
spacing: space,
|
}, peerSearchText),
|
||||||
runSpacing: space))),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user