Skip to content

Commit

Permalink
fix: add workaround for flutter hot reload bug (#210)
Browse files Browse the repository at this point in the history
Fixes #209
  • Loading branch information
GregoryConrad authored Aug 17, 2024
1 parent 42123e7 commit 702a757
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/flutter_rearch/lib/src/widgets/consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,24 @@ class _RearchElement extends ComponentElement {
// We need to do some dependency management here to ensure that we
// get all the capsule updates we need, but nothing more.

// First, let's remove any no-longer used dependencies.
capsuleToRemoveDependency.entries
.where((e) => !capsulesUsedInCurrBuild!.contains(e.key))
.toList()
.forEach((e) {
e.value(); // dispose() from onNextUpdate
capsuleToRemoveDependency.remove(e.key);
});

// Next, for each capsule used in the current build,
// let's make sure we depend upon it.
capsulesUsedInCurrBuild!
.where((cap) => !capsuleToRemoveDependency.containsKey(cap))
.forEach((cap) {
capsuleToRemoveDependency[cap] = container.onNextUpdate(cap, () {
markNeedsBuild();
capsuleToRemoveDependency.remove(cap);
});
// First, ensure we depend upon every capsule used in the current build.
for (final capsule in capsulesUsedInCurrBuild!) {
capsuleToRemoveDependency.putIfAbsent(
capsule,
() => container.onNextUpdate(capsule, () {
markNeedsBuild();
capsuleToRemoveDependency.remove(capsule);
}),
);
}

// Next, remove any no-longer used dependencies.
capsuleToRemoveDependency.keys
.toSet()
.difference(capsulesUsedInCurrBuild!)
.forEach((capsule) {
// NOTE: this will call the dispose() returned from onNextUpdate
capsuleToRemoveDependency.remove(capsule)!.call();
});

// Finally, let's reset everything for the next build.
Expand Down

0 comments on commit 702a757

Please sign in to comment.