Skip to content

Commit

Permalink
feat: add a delay before displaying progress indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
henri2h committed Apr 1, 2022
1 parent 8c27501 commit 6f9e622
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class _MaterialControlsState extends State<MaterialControls>
absorbing: notifier.hideStuff,
child: Stack(
children: [
if (_latestValue.isBuffering)
if (displayLoading)
const Center(
child: CircularProgressIndicator(),
)
Expand Down Expand Up @@ -547,8 +547,27 @@ class _MaterialControlsState extends State<MaterialControls>
});
}

Timer? timerInstance;
bool displayLoading = false;

void handleTimeout() {
displayLoading = true;
if (mounted) {
setState(() {});
}
}

void _updateState() {
if (!mounted) return;

if (controller.value.isBuffering) {
timerInstance ??= Timer(const Duration(milliseconds: 200), handleTimeout);
} else {
timerInstance?.cancel();
timerInstance = null;
displayLoading = false;
}

setState(() {
_latestValue = controller.value;
_subtitlesPosition = controller.value.position;
Expand Down

0 comments on commit 6f9e622

Please sign in to comment.