Skip to content

Commit

Permalink
fix: Pop all events from stack
Browse files Browse the repository at this point in the history
It can happen that the dialog is not able to render before the next event is received. Before that patch that could have lead to some random dangling events that get shown once the root screen gets rebuild.

This patch puts new events in a last in last out order and on rendering the task dialog pops all events from the queue. This way we prevent having dangling events.

fixes #2506
  • Loading branch information
holzeis committed May 8, 2024
1 parent 3d032d5 commit 0b5542b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mobile/lib/common/background_task_change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:get_10101/logger/logger.dart';
class Stack<E> {
final _list = <E>[];

void push(E value) => _list.add(value);
void push(E value) => _list.insert(0, value);

E pop() => _list.removeLast();

Expand Down
8 changes: 7 additions & 1 deletion mobile/lib/common/background_task_dialog_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ class _BackgroundTaskDialogScreenState extends State<BackgroundTaskDialogScreen>
pageBuilder: (context, _, __) {
// watch task updates from within the dialog.
try {
final task = context.watch<BackgroundTaskChangeNotifier>().events.pop();
final events = context.watch<BackgroundTaskChangeNotifier>().events;
var task = events.pop();
while (events.isNotEmpty) {
// we might have received very fast events. In that case we pop until we are at
// the latest event.
task = events.pop();
}
if (activeTask != null && task.type != activeTask!.type) {
logger.w("Received another task event $task while $activeTask is still active!");
}
Expand Down

0 comments on commit 0b5542b

Please sign in to comment.