From d2b6c3bd2db4fa3154a7d678f8ec6baa749855c8 Mon Sep 17 00:00:00 2001 From: Mikolaj Kieres Date: Wed, 13 Jul 2022 14:47:22 -0700 Subject: [PATCH] fixing an issue with expansions not being separated correctly from the main games (#110) --- .../lib/models/hive/board_game_details.dart | 2 ++ .../board_game_details_expansions.dart | 13 +++++-------- .../lib/pages/games/games_view_model.dart | 7 ++++--- .../lib/stores/board_games_store.dart | 9 +++++---- .../widgets/common/expansions_banner_widget.dart | 5 ----- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/board_games_companion/lib/models/hive/board_game_details.dart b/board_games_companion/lib/models/hive/board_game_details.dart index f2f5eba4..56276724 100644 --- a/board_games_companion/lib/models/hive/board_game_details.dart +++ b/board_games_companion/lib/models/hive/board_game_details.dart @@ -201,6 +201,8 @@ class BoardGameDetails extends BaseBoardGame { } } + bool get isMainGame => !(isExpansion ?? false); + bool? _isOwned; @HiveField(24) bool? get isOwned => _isOwned ?? false; diff --git a/board_games_companion/lib/pages/board_game_details/board_game_details_expansions.dart b/board_games_companion/lib/pages/board_game_details/board_game_details_expansions.dart index d380ae14..7691a4f7 100644 --- a/board_games_companion/lib/pages/board_game_details/board_game_details_expansions.dart +++ b/board_games_companion/lib/pages/board_game_details/board_game_details_expansions.dart @@ -118,7 +118,7 @@ class _Expansion extends StatelessWidget { @override Widget build(BuildContext context) { - Widget expansionItemWidget = InkWell( + Widget expansionItem = InkWell( splashColor: AppTheme.accentColor, child: Padding( padding: const EdgeInsets.symmetric( @@ -134,10 +134,7 @@ class _Expansion extends StatelessWidget { style: AppTheme.theme.textTheme.headline3, ), ), - const Icon( - Icons.navigate_next, - color: AppTheme.accentColor, - ), + const Icon(Icons.navigate_next, color: AppTheme.accentColor), ], ), ), @@ -155,21 +152,21 @@ class _Expansion extends StatelessWidget { ); if (_boardGameExpansion.isInCollection ?? false) { - expansionItemWidget = ClipRect( + expansionItem = ClipRect( child: CustomPaint( foregroundPainter: ExpanionsBannerPainter( location: BannerLocation.topStart, color: AppTheme.accentColor, message: 'own', ), - child: expansionItemWidget, + child: expansionItem, ), ); } return Material( color: Colors.transparent, - child: expansionItemWidget, + child: expansionItem, ); } } diff --git a/board_games_companion/lib/pages/games/games_view_model.dart b/board_games_companion/lib/pages/games/games_view_model.dart index 345e0d24..4fee450b 100644 --- a/board_games_companion/lib/pages/games/games_view_model.dart +++ b/board_games_companion/lib/pages/games/games_view_model.dart @@ -121,9 +121,10 @@ class GamesViewModel with ChangeNotifier { await _boardGamesStore.loadBoardGames(); for (final boardGameDetails in _boardGamesStore.allBoardGames) { _filteredBoardGames[boardGameDetails.id] = boardGameDetails; - for (final boardGameExpansion in boardGameDetails.expansions) { - _mainBoardGameByExpansionId[boardGameExpansion.id] = boardGameDetails; - } + if (boardGameDetails.isMainGame) + for (final boardGameExpansion in boardGameDetails.expansions) { + _mainBoardGameByExpansionId[boardGameExpansion.id] = boardGameDetails; + } } await _boardGamesFiltersStore.loadFilterPreferences(); diff --git a/board_games_companion/lib/stores/board_games_store.dart b/board_games_companion/lib/stores/board_games_store.dart index e22882eb..37a21673 100644 --- a/board_games_companion/lib/stores/board_games_store.dart +++ b/board_games_companion/lib/stores/board_games_store.dart @@ -91,10 +91,8 @@ class BoardGamesStore with ChangeNotifier { BoardGameDetails existingBoardGameDetails, BoardGameDetails boardGameDetails, ) { - existingBoardGameDetails.expansions = boardGameDetails.expansions; - -// MK If updating an expansion, update IsInCollection flag for the parent board game - if (boardGameDetails.isExpansion!) { + if (boardGameDetails.isExpansion ?? false) { + // MK If updating an expansion, find the main game and update IsInCollection flag for this expansion final BoardGamesExpansion? parentBoardGameExpansion = allBoardGames .expand((BoardGameDetails boardGameDetails) => boardGameDetails.expansions) .firstWhereOrNull( @@ -105,6 +103,9 @@ class BoardGamesStore with ChangeNotifier { if (parentBoardGameExpansion != null) { parentBoardGameExpansion.isInCollection = boardGameDetails.isOwned; } + } else { + // MK Update main board game expansions list + existingBoardGameDetails.expansions = boardGameDetails.expansions; } } diff --git a/board_games_companion/lib/widgets/common/expansions_banner_widget.dart b/board_games_companion/lib/widgets/common/expansions_banner_widget.dart index 4b9394ab..f802fd30 100644 --- a/board_games_companion/lib/widgets/common/expansions_banner_widget.dart +++ b/board_games_companion/lib/widgets/common/expansions_banner_widget.dart @@ -36,15 +36,11 @@ class ExpanionsBannerPainter extends CustomPainter { /// Defaults to a dark red. final Color color; - static const BoxShadow _shadow = AppTheme.defaultBoxShadow; - bool _prepared = false; late TextPainter _textPainter; - late Paint _paintShadow; late Paint _paintBanner; void _prepare() { - _paintShadow = _shadow.toPaint(); _paintBanner = Paint()..color = color; _textPainter = TextPainter( text: TextSpan( @@ -68,7 +64,6 @@ class ExpanionsBannerPainter extends CustomPainter { canvas ..translate(_translationX(size.width), _translationY(size.height)) ..rotate(_rotation) - ..drawRect(_kRect, _paintShadow) ..drawRect(_kRect, _paintBanner); const double width = _kOffset * 2.0; _textPainter.layout(minWidth: width, maxWidth: width);