Skip to content

Commit

Permalink
fixing an issue with expansions not being separated correctly from th…
Browse files Browse the repository at this point in the history
…e main games (#110)
  • Loading branch information
mkieres authored Jul 13, 2022
1 parent 980c39c commit d2b6c3b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
2 changes: 2 additions & 0 deletions board_games_companion/lib/models/hive/board_game_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ class BoardGameDetails extends BaseBoardGame {
}
}

bool get isMainGame => !(isExpansion ?? false);

bool? _isOwned;
@HiveField(24)
bool? get isOwned => _isOwned ?? false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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),
],
),
),
Expand All @@ -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,
);
}
}
7 changes: 4 additions & 3 deletions board_games_companion/lib/pages/games/games_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions board_games_companion/lib/stores/board_games_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down

0 comments on commit d2b6c3b

Please sign in to comment.