Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
@override
Widget buildViewWithOptions(VideoViewOptions options) {
final int playerId = options.playerId;
if (!_players.containsKey(playerId)) {
return Container();
}
Comment on lines +213 to +215
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic change should be accompanied by a unit test to verify that buildViewWithOptions correctly handles missing player IDs by returning an empty widget instead of throwing an exception. Per the repository style guide, all code changes should be tested to ensure correctness and prevent regressions.

References
  1. Code should be tested. Changes to plugin packages should have appropriate tests. (link)

final VideoPlayerViewState viewState = _playerWith(id: playerId).viewState;
Comment on lines +213 to 216
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using const SizedBox.shrink() is preferred over Container() for returning an empty widget as it is more lightweight and idiomatic in Flutter. Additionally, this approach avoids a redundant map lookup by retrieving the player instance once and checking for null, rather than using containsKey followed by _playerWith (which performs another lookup and throws).

Suggested change
if (!_players.containsKey(playerId)) {
return Container();
}
final VideoPlayerViewState viewState = _playerWith(id: playerId).viewState;
final _PlayerInstance? player = _players[playerId];
if (player == null) {
return const SizedBox.shrink();
}
final VideoPlayerViewState viewState = player.viewState;
References
  1. Code should follow the relevant style guides (Flutter/Dart) which prefer SizedBox.shrink() for empty widgets. (link)


return switch (viewState) {
Expand Down