Revert "fix peers view ChangeNotifierProvider update (#9459)" (#9471)

This reverts commit 7c55e3266b1cf13a92e6973323aba3034651afb1.
This commit is contained in:
RustDesk 2024-09-26 14:20:37 +08:00 committed by GitHub
parent 6d8b5b289f
commit c74bdcdfdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -128,8 +128,7 @@ class _PeersViewState extends State<_PeersView>
// //
// Although `onWindowRestore()` is called after `onWindowBlur()` in my test, // Although `onWindowRestore()` is called after `onWindowBlur()` in my test,
// we need the following comparison to ensure that `_isActive` is true in the end. // we need the following comparison to ensure that `_isActive` is true in the end.
if (isWindows && if (isWindows && DateTime.now().difference(_lastWindowRestoreTime) <
DateTime.now().difference(_lastWindowRestoreTime) <
const Duration(milliseconds: 300)) { const Duration(milliseconds: 300)) {
return; return;
} }
@ -171,9 +170,8 @@ class _PeersViewState extends State<_PeersView>
// We should avoid too many rebuilds. MacOS(m1, 14.6.1) on Flutter 3.19.6. // We should avoid too many rebuilds. MacOS(m1, 14.6.1) on Flutter 3.19.6.
// Continious rebuilds of `ChangeNotifierProvider` will cause memory leak. // Continious rebuilds of `ChangeNotifierProvider` will cause memory leak.
// Simple demo can reproduce this issue. // Simple demo can reproduce this issue.
return ChangeNotifierProvider<Peers>.value( return ChangeNotifierProvider<Peers>(
// https://pub.dev/packages/provider: If you already have an object instance and want to expose it, it would be best to use the .value constructor of a provider. create: (context) => widget.peers,
value: widget.peers,
child: Consumer<Peers>(builder: (context, peers, child) { child: Consumer<Peers>(builder: (context, peers, child) {
if (peers.peers.isEmpty) { if (peers.peers.isEmpty) {
gFFI.peerTabModel.setCurrentTabCachedPeers([]); gFFI.peerTabModel.setCurrentTabCachedPeers([]);
@ -188,7 +186,7 @@ class _PeersViewState extends State<_PeersView>
).paddingOnly(bottom: 10), ).paddingOnly(bottom: 10),
Text( Text(
translate( translate(
_emptyMessages[peers.loadEvent] ?? 'Empty', _emptyMessages[widget.peers.loadEvent] ?? 'Empty',
), ),
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(