change total assets before emitting the reload event

This commit is contained in:
shenlong-tanwen 2025-07-09 08:17:51 +05:30
parent 9ab0c604ea
commit e375736f27

View File

@ -129,11 +129,11 @@ class TimelineService {
if (totalAssets == 0) {
_bufferOffset = 0;
_buffer.clear();
// When the buffer is empty or the old bufferOffset is greater than the new total assets,
// we need to reset the buffer and load the first batch of assets.
} else {
final int offset;
final int count;
// When the buffer is empty or the old bufferOffset is greater than the new total assets,
// we need to reset the buffer and load the first batch of assets.
if (_bufferOffset >= totalAssets || _buffer.isEmpty) {
offset = 0;
count = kTimelineAssetLoadBatchSize;
@ -148,9 +148,9 @@ class TimelineService {
_bufferOffset = offset;
}
EventStream.shared.emit(const TimelineReloadEvent());
// change the state's total assets count only after the buffer is reloaded
_totalAssets = totalAssets;
EventStream.shared.emit(const TimelineReloadEvent());
});
});
}