From dab8fc6cc9c8b13e7afc52ac6aa6f35d9f9143f1 Mon Sep 17 00:00:00 2001 From: fufesou Date: Thu, 28 Jul 2022 14:06:02 +0800 Subject: [PATCH] flutter_desktop: load popup menu items onTap Signed-off-by: fufesou --- flutter/lib/desktop/widgets/peer_widget.dart | 4 ++++ .../lib/desktop/widgets/peercard_widget.dart | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/flutter/lib/desktop/widgets/peer_widget.dart b/flutter/lib/desktop/widgets/peer_widget.dart index e0c82bb30..42cb8eb1d 100644 --- a/flutter/lib/desktop/widgets/peer_widget.dart +++ b/flutter/lib/desktop/widgets/peer_widget.dart @@ -167,6 +167,7 @@ class RecentPeerWidget extends BasePeerWidget { } Future> _loadPeers() async { + debugPrint("call RecentPeerWidget _loadPeers"); return gFFI.peers(); } } @@ -180,6 +181,7 @@ class FavoritePeerWidget extends BasePeerWidget { @override Future> _loadPeers() async { + debugPrint("call FavoritePeerWidget _loadPeers"); return await gFFI.bind.mainGetFav().then((peers) async { final peersEntities = await Future.wait(peers .map((id) => gFFI.bind.mainGetPeers(id: id)) @@ -206,6 +208,7 @@ class DiscoveredPeerWidget extends BasePeerWidget { } Future> _loadPeers() async { + debugPrint("call DiscoveredPeerWidget _loadPeers"); return await gFFI.bind.mainGetLanPeers().then((peers_string) { debugPrint(peers_string); return []; @@ -222,6 +225,7 @@ class AddressBookPeerWidget extends BasePeerWidget { } Future> _loadPeers() async { + debugPrint("call AddressBookPeerWidget _loadPeers"); return gFFI.abModel.peers.map((e) { return Peer.fromJson(e['id'], e); }).toList(); diff --git a/flutter/lib/desktop/widgets/peercard_widget.dart b/flutter/lib/desktop/widgets/peercard_widget.dart index b8c6d54de..02b146457 100644 --- a/flutter/lib/desktop/widgets/peercard_widget.dart +++ b/flutter/lib/desktop/widgets/peercard_widget.dart @@ -7,11 +7,13 @@ import '../../common.dart'; import '../../models/model.dart'; import '../../models/peer_model.dart'; +typedef PopupMenuItemsFunc = Future>> Function(); + class _PeerCard extends StatefulWidget { final Peer peer; - final List> popupMenuItems; + final PopupMenuItemsFunc popupMenuItemsFunc; - _PeerCard({required this.peer, required this.popupMenuItems, Key? key}) + _PeerCard({required this.peer, required this.popupMenuItemsFunc, Key? key}) : super(key: key); @override @@ -148,7 +150,7 @@ class _PeerCardState extends State<_PeerCard> { var value = await showMenu( context: context, position: this._menuPos, - items: super.widget.popupMenuItems, + items: await super.widget.popupMenuItemsFunc(), elevation: 8, ); if (value == 'remove') { @@ -271,17 +273,18 @@ abstract class BasePeerCard extends StatelessWidget { @override Widget build(BuildContext context) { - return _PeerCard(peer: peer, popupMenuItems: _getPopupMenuItems()); + return _PeerCard(peer: peer, popupMenuItemsFunc: _getPopupMenuItems); } @protected - List> _getPopupMenuItems(); + Future>> _getPopupMenuItems(); } class RecentPeerCard extends BasePeerCard { RecentPeerCard({required Peer peer, Key? key}) : super(peer: peer, key: key); - List> _getPopupMenuItems() { + Future>> _getPopupMenuItems() async { + debugPrint("call RecentPeerCard _getPopupMenuItems"); return [ PopupMenuItem( child: Text(translate('Connect')), value: 'connect'), @@ -304,7 +307,8 @@ class FavoritePeerCard extends BasePeerCard { FavoritePeerCard({required Peer peer, Key? key}) : super(peer: peer, key: key); - List> _getPopupMenuItems() { + Future>> _getPopupMenuItems() async { + debugPrint("call FavoritePeerCard _getPopupMenuItems"); return [ PopupMenuItem( child: Text(translate('Connect')), value: 'connect'), @@ -327,7 +331,8 @@ class DiscoveredPeerCard extends BasePeerCard { DiscoveredPeerCard({required Peer peer, Key? key}) : super(peer: peer, key: key); - List> _getPopupMenuItems() { + Future>> _getPopupMenuItems() async { + debugPrint("call DiscoveredPeerCard _getPopupMenuItems"); return [ PopupMenuItem( child: Text(translate('Connect')), value: 'connect'), @@ -350,7 +355,8 @@ class AddressBookPeerCard extends BasePeerCard { AddressBookPeerCard({required Peer peer, Key? key}) : super(peer: peer, key: key); - List> _getPopupMenuItems() { + Future>> _getPopupMenuItems() async { + debugPrint("call AddressBookPeerCard _getPopupMenuItems"); return [ PopupMenuItem( child: Text(translate('Connect')), value: 'connect'),