fix peers view ChangeNotifierProvider update (#9459)
Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
parent
ce5151032e
commit
7c55e3266b
@ -128,8 +128,9 @@ 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 && DateTime.now().difference(_lastWindowRestoreTime) <
|
if (isWindows &&
|
||||||
const Duration(milliseconds: 300)) {
|
DateTime.now().difference(_lastWindowRestoreTime) <
|
||||||
|
const Duration(milliseconds: 300)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_queryCount = _maxQueryCount;
|
_queryCount = _maxQueryCount;
|
||||||
@ -170,8 +171,9 @@ 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>(
|
return ChangeNotifierProvider<Peers>.value(
|
||||||
create: (context) => widget.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.
|
||||||
|
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([]);
|
||||||
@ -186,7 +188,7 @@ class _PeersViewState extends State<_PeersView>
|
|||||||
).paddingOnly(bottom: 10),
|
).paddingOnly(bottom: 10),
|
||||||
Text(
|
Text(
|
||||||
translate(
|
translate(
|
||||||
_emptyMessages[widget.peers.loadEvent] ?? 'Empty',
|
_emptyMessages[peers.loadEvent] ?? 'Empty',
|
||||||
),
|
),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user