Skip to content

Commit

Permalink
fix: support scheduling transactions while building (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed Sep 7, 2022
1 parent 6bc4079 commit 0cb5d90
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/fleet/lib/src/transaction.dart
Expand Up @@ -218,7 +218,15 @@ mixin TransactionBinding on BindingBase, RendererBinding {

Timeline.startSync('TRANSACTIONS');

for (final entry in _scheduledTransactions) {
// We explicitly support scheduling transactions while building.
// This is useful when a state change is needed to trigger some action that
// should start immediately and not in the next frame. For example, starting
// an animation when a widget is built for the first time.
//
// Because of that we cannot iterate the list of scheduled transactions
// because it might be modified by the build.
while (_scheduledTransactions.isNotEmpty) {
final entry = _scheduledTransactions.removeAt(0);
final transaction = entry.key;
final callback = entry.value;

Expand All @@ -228,8 +236,6 @@ mixin TransactionBinding on BindingBase, RendererBinding {
debugBuildingDirtyElements = true;
}

_scheduledTransactions.clear();

Timeline.finishSync();
}

Expand Down

0 comments on commit 0cb5d90

Please sign in to comment.