Skip to content

Feature Suggestion: "Debouncing" option #87

@Lofter1

Description

@Lofter1

It would be nice to have an option to "debounce" the Loading Overlay. If I'm not sure whether an asynchronous call will be processed virtually instantaneously or maybe take a bit I will wrap it in the show() and hide calls. However, if the asynchronous call is "too fast", this will result in an annoying "visual pop" where the loader is being shown and then instantly hidden again.

In an extension method I've written to use in future builders I've currently solved this by using a timer:

extension OverlayLoaderExtension on OverlayExtensionHelper {
  static Timer? _debounceTimer;

  void snapshotLoader(
    AsyncSnapshot asyncSnapshot, {
    Duration delay = const Duration(milliseconds: 150),
  }) {
    if (asyncSnapshot.connectionState == ConnectionState.waiting) {
      _debounceTimer?.cancel();
      _debounceTimer = Timer(delay, () {
        show();
      });
    } else {
      _debounceTimer?.cancel();
      _debounceTimer = null;
      hide();
    }
  }
}

This works very well to prevent the visual "pop" if my data loads quickly.

It would be nice to have a similar option when initialising the overlay to enable a global "debouncing".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions