diff --git a/board_games_companion/lib/extensions/players_extensions.dart b/board_games_companion/lib/extensions/players_extensions.dart new file mode 100644 index 00000000..43227841 --- /dev/null +++ b/board_games_companion/lib/extensions/players_extensions.dart @@ -0,0 +1,7 @@ +import '../models/hive/player.dart'; + +extension PlayersExtensions on List { + List sortAlphabetically() { + return [...this]..sort((player, otherPlayer) => player.name!.compareTo(otherPlayer.name!)); + } +} diff --git a/board_games_companion/lib/models/hive/player.dart b/board_games_companion/lib/models/hive/player.dart index a6e798ef..ddfe4f64 100644 --- a/board_games_companion/lib/models/hive/player.dart +++ b/board_games_companion/lib/models/hive/player.dart @@ -5,6 +5,8 @@ import 'package:image_picker/image_picker.dart'; import '../../common/constants.dart'; import '../../common/hive_boxes.dart'; +export '../../extensions/players_extensions.dart'; + part 'player.freezed.dart'; part 'player.g.dart'; diff --git a/board_games_companion/lib/pages/playthroughs/playthrough_players_selection_view_model.dart b/board_games_companion/lib/pages/playthroughs/playthrough_players_selection_view_model.dart index 6ad243f3..64b72b3e 100644 --- a/board_games_companion/lib/pages/playthroughs/playthrough_players_selection_view_model.dart +++ b/board_games_companion/lib/pages/playthroughs/playthrough_players_selection_view_model.dart @@ -18,9 +18,8 @@ abstract class _PlaythroughPlayersSelectionViewModel with Store { final PlayersStore _playersStore; @computed - ObservableList get players => ([..._playersStore.players] - ..sort((player, otherPlayer) => player.name!.compareTo(otherPlayer.name!))) - .asObservable(); + ObservableList get players => + ([..._playersStore.players].sortAlphabetically()).asObservable(); @computed Map get playersMap => {for (final player in players) player.id: player}; diff --git a/board_games_companion/lib/pages/playthroughs/playthroughs_log_game_page.dart b/board_games_companion/lib/pages/playthroughs/playthroughs_log_game_page.dart index 7cbb4ad0..8a99ffe7 100644 --- a/board_games_companion/lib/pages/playthroughs/playthroughs_log_game_page.dart +++ b/board_games_companion/lib/pages/playthroughs/playthroughs_log_game_page.dart @@ -115,24 +115,22 @@ class PlaythroughsLogGamePageState extends State { }, ), Observer( - builder: (_) { - return _PlayersSection( - playthroughTimeline: viewModel.playthroughTimeline, - gameFamily: viewModel.gameFamily, - players: viewModel.playersState, - onCreatePlayer: () => _handleCreatePlayer(), - onSelectPlayers: () => _handleSelectPlayers(), - onPlayerScoreUpdated: (playerScore, score) => - _handlePlayerScoreUpdate(playerScore, score), - ); - }, + builder: (_) => _PlayersSection( + playthroughTimeline: viewModel.playthroughTimeline, + gameFamily: viewModel.gameFamily, + players: viewModel.playersState, + onCreatePlayer: () => _handleCreatePlayer(), + onSelectPlayers: () => _handleSelectPlayers(), + onPlayerScoreUpdated: (playerScore, score) => + _handlePlayerScoreUpdate(playerScore, score), + ), ), - Observer(builder: (_) { - return _SubmitSection( + Observer( + builder: (_) => _SubmitSection( players: viewModel.playersState, onLogPlaythrough: () => _handleLoggingPlaythrough(), - ); - }), + ), + ), ], ); } diff --git a/board_games_companion/lib/pages/playthroughs/playthroughs_log_game_view_model.dart b/board_games_companion/lib/pages/playthroughs/playthroughs_log_game_view_model.dart index 1c0d4513..575ef223 100644 --- a/board_games_companion/lib/pages/playthroughs/playthroughs_log_game_view_model.dart +++ b/board_games_companion/lib/pages/playthroughs/playthroughs_log_game_view_model.dart @@ -131,7 +131,7 @@ abstract class _PlaythroughsLogGameViewModel with Store { } playersState = PlaythroughsLogGamePlayers.playersSelected( - players: selectedPlayers, + players: selectedPlayers.sortAlphabetically(), playerScores: playerScores, ); }