refactor: rename to peer_card.dart and peers_view.dart

This commit is contained in:
csf 2022-09-22 15:35:46 +08:00
parent 36cd262227
commit 9bbc3376a4
6 changed files with 40 additions and 41 deletions

View File

@ -1,6 +1,6 @@
import 'package:contextmenu/contextmenu.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/widgets/peer_widget.dart';
import 'package:flutter_hbb/common/widgets/peers_view.dart';
import 'package:flutter_hbb/models/ab_model.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
@ -174,7 +174,7 @@ class _AddressBookState extends State<AddressBook> {
Expanded(
child: Align(
alignment: Alignment.topLeft,
child: AddressBookPeerWidget()),
child: AddressBookPeersView()),
)
],
));

View File

@ -489,7 +489,6 @@ abstract class BasePeerCard extends StatelessWidget {
await bind.mainRemovePeer(id: id);
removePreference(id);
await reloadFunc();
// Get.forceAppUpdate(); // TODO use inner model / state
}();
},
dismissOnClicked: true,

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/widgets/peer_widget.dart';
import 'package:flutter_hbb/common/widgets/peercard_widget.dart';
import 'package:flutter_hbb/common/widgets/peers_view.dart';
import 'package:flutter_hbb/common/widgets/peer_card.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:get/get.dart';

View File

@ -11,34 +11,34 @@ import 'package:window_manager/window_manager.dart';
import '../../common.dart';
import '../../models/peer_model.dart';
import '../../models/platform_model.dart';
import 'peercard_widget.dart';
import 'peer_card.dart';
typedef OffstageFunc = bool Function(Peer peer);
typedef PeerCardWidgetFunc = Widget Function(Peer peer);
typedef PeerCardBuilder = BasePeerCard Function(Peer peer);
/// for peer search text, global obs value
final peerSearchText = "".obs;
final peerSearchTextController =
TextEditingController(text: peerSearchText.value);
class _PeerWidget extends StatefulWidget {
class _PeersView extends StatefulWidget {
final Peers peers;
final OffstageFunc offstageFunc;
final PeerCardWidgetFunc peerCardWidgetFunc;
final PeerCardBuilder peerCardBuilder;
const _PeerWidget(
const _PeersView(
{required this.peers,
required this.offstageFunc,
required this.peerCardWidgetFunc,
required this.peerCardBuilder,
Key? key})
: super(key: key);
@override
_PeerWidgetState createState() => _PeerWidgetState();
_PeersViewState createState() => _PeersViewState();
}
/// State for the peer widget.
class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
class _PeersViewState extends State<_PeersView> with WindowListener {
static const int _maxQueryCount = 3;
final space = isDesktop ? 12.0 : 8.0;
final _curPeers = <String>{};
@ -60,7 +60,7 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
return width;
}();
_PeerWidgetState() {
_PeersViewState() {
_startCheckOnlines();
}
@ -119,7 +119,7 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
}
_lastChangeTime = DateTime.now();
},
child: widget.peerCardWidgetFunc(peer),
child: widget.peerCardBuilder(peer),
);
cards.add(Offstage(
key: ValueKey("off${peer.id}"),
@ -198,39 +198,39 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
}
}
abstract class BasePeerWidget extends StatelessWidget {
abstract class BasePeersView extends StatelessWidget {
final String name;
final String loadEvent;
final OffstageFunc offstageFunc;
final PeerCardWidgetFunc peerCardWidgetFunc;
final PeerCardBuilder peerCardBuilder;
final List<Peer> initPeers;
const BasePeerWidget({
const BasePeersView({
Key? key,
required this.name,
required this.loadEvent,
required this.offstageFunc,
required this.peerCardWidgetFunc,
required this.peerCardBuilder,
required this.initPeers,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return _PeerWidget(
return _PeersView(
peers: Peers(name: name, loadEvent: loadEvent, peers: initPeers),
offstageFunc: offstageFunc,
peerCardWidgetFunc: peerCardWidgetFunc);
peerCardBuilder: peerCardBuilder);
}
}
class RecentPeerWidget extends BasePeerWidget {
RecentPeerWidget({Key? key})
class RecentPeersView extends BasePeersView {
RecentPeersView({Key? key})
: super(
key: key,
name: 'recent peer',
loadEvent: 'load_recent_peers',
offstageFunc: (Peer peer) => false,
peerCardWidgetFunc: (Peer peer) => RecentPeerCard(
peerCardBuilder: (Peer peer) => RecentPeerCard(
peer: peer,
),
initPeers: [],
@ -244,14 +244,14 @@ class RecentPeerWidget extends BasePeerWidget {
}
}
class FavoritePeerWidget extends BasePeerWidget {
FavoritePeerWidget({Key? key})
class FavoritePeersView extends BasePeersView {
FavoritePeersView({Key? key})
: super(
key: key,
name: 'favorite peer',
loadEvent: 'load_fav_peers',
offstageFunc: (Peer peer) => false,
peerCardWidgetFunc: (Peer peer) => FavoritePeerCard(
peerCardBuilder: (Peer peer) => FavoritePeerCard(
peer: peer,
),
initPeers: [],
@ -265,14 +265,14 @@ class FavoritePeerWidget extends BasePeerWidget {
}
}
class DiscoveredPeerWidget extends BasePeerWidget {
DiscoveredPeerWidget({Key? key})
class DiscoveredPeersView extends BasePeersView {
DiscoveredPeersView({Key? key})
: super(
key: key,
name: 'discovered peer',
loadEvent: 'load_lan_peers',
offstageFunc: (Peer peer) => false,
peerCardWidgetFunc: (Peer peer) => DiscoveredPeerCard(
peerCardBuilder: (Peer peer) => DiscoveredPeerCard(
peer: peer,
),
initPeers: [],
@ -286,15 +286,15 @@ class DiscoveredPeerWidget extends BasePeerWidget {
}
}
class AddressBookPeerWidget extends BasePeerWidget {
AddressBookPeerWidget({Key? key})
class AddressBookPeersView extends BasePeersView {
AddressBookPeersView({Key? key})
: super(
key: key,
name: 'address book peer',
loadEvent: 'load_address_book_peers',
offstageFunc: (Peer peer) =>
!_hitTag(gFFI.abModel.selectedTags, peer.tags),
peerCardWidgetFunc: (Peer peer) => AddressBookPeerCard(
peerCardBuilder: (Peer peer) => AddressBookPeerCard(
peer: peer,
),
initPeers: _loadPeers(),

View File

@ -11,7 +11,7 @@ import 'package:url_launcher/url_launcher_string.dart';
import '../../common.dart';
import '../../common/formatter/id_formatter.dart';
import '../../common/widgets/peer_tab_page.dart';
import '../../common/widgets/peer_widget.dart';
import '../../common/widgets/peers_view.dart';
import '../../models/platform_model.dart';
/// Connection page for connecting to a remote peer.
@ -74,9 +74,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
translate('Address Book')
],
children: [
RecentPeerWidget(),
FavoritePeerWidget(),
DiscoveredPeerWidget(),
RecentPeersView(),
FavoritePeersView(),
DiscoveredPeersView(),
const AddressBook(),
],
)),

View File

@ -10,7 +10,7 @@ import 'package:url_launcher/url_launcher.dart';
import '../../common.dart';
import '../../common/widgets/address_book.dart';
import '../../common/widgets/peer_tab_page.dart';
import '../../common/widgets/peer_widget.dart';
import '../../common/widgets/peers_view.dart';
import '../../consts.dart';
import '../../models/model.dart';
import '../../models/platform_model.dart';
@ -84,9 +84,9 @@ class _ConnectionPageState extends State<ConnectionPage> {
translate('Address Book')
],
children: [
RecentPeerWidget(),
FavoritePeerWidget(),
DiscoveredPeerWidget(),
RecentPeersView(),
FavoritePeersView(),
DiscoveredPeersView(),
const AddressBook(),
],
)),