Skip to content

Bug: Exiting video player blocks UI navigation on network request #12

@windoze95

Description

@windoze95

Problem

In lib/screens/video_player_screen.dart (around line 318), the _navigateBack() method looks like this:

  Future<void> _navigateBack() async {
    // Save progress before leaving, then invalidate so lists refresh
    if (_controller != null && _controller!.value.isInitialized) {
      final position = _controller!.value.position.inSeconds;
      if (position > 0) {
        await _api.updateProgress(widget.videoId, position);
      }
    }
    _controller?.pause();
    if (mounted) {
      Navigator.of(context).pop();
    }
  }

If the user hits the back button (or Android hardware back button), the UI is blocked waiting for the network request await _api.updateProgress(...) to finish. If the connection is slow or drops, the screen will hang on the video player before popping.

Suggested Fix

Remove the await from the _api.updateProgress call in _navigateBack(), allowing the network request to complete in the background (fire-and-forget), and immediately call _controller?.pause(); Navigator.pop(). Note that you also need to ensure ApiService isn't instantly disposed or cancelled before the background request completes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions