flutter_desktop: load popup menu items onTap

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-07-28 14:06:02 +08:00
parent 279a38a7f2
commit dab8fc6cc9
2 changed files with 19 additions and 9 deletions

View File

@ -167,6 +167,7 @@ class RecentPeerWidget extends BasePeerWidget {
}
Future<List<Peer>> _loadPeers() async {
debugPrint("call RecentPeerWidget _loadPeers");
return gFFI.peers();
}
}
@ -180,6 +181,7 @@ class FavoritePeerWidget extends BasePeerWidget {
@override
Future<List<Peer>> _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<List<Peer>> _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<List<Peer>> _loadPeers() async {
debugPrint("call AddressBookPeerWidget _loadPeers");
return gFFI.abModel.peers.map((e) {
return Peer.fromJson(e['id'], e);
}).toList();

View File

@ -7,11 +7,13 @@ import '../../common.dart';
import '../../models/model.dart';
import '../../models/peer_model.dart';
typedef PopupMenuItemsFunc = Future<List<PopupMenuItem<String>>> Function();
class _PeerCard extends StatefulWidget {
final Peer peer;
final List<PopupMenuItem<String>> 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<PopupMenuItem<String>> _getPopupMenuItems();
Future<List<PopupMenuItem<String>>> _getPopupMenuItems();
}
class RecentPeerCard extends BasePeerCard {
RecentPeerCard({required Peer peer, Key? key}) : super(peer: peer, key: key);
List<PopupMenuItem<String>> _getPopupMenuItems() {
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
debugPrint("call RecentPeerCard _getPopupMenuItems");
return [
PopupMenuItem<String>(
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<PopupMenuItem<String>> _getPopupMenuItems() {
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
debugPrint("call FavoritePeerCard _getPopupMenuItems");
return [
PopupMenuItem<String>(
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<PopupMenuItem<String>> _getPopupMenuItems() {
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
debugPrint("call DiscoveredPeerCard _getPopupMenuItems");
return [
PopupMenuItem<String>(
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<PopupMenuItem<String>> _getPopupMenuItems() {
Future<List<PopupMenuItem<String>>> _getPopupMenuItems() async {
debugPrint("call AddressBookPeerCard _getPopupMenuItems");
return [
PopupMenuItem<String>(
child: Text(translate('Connect')), value: 'connect'),