Skip to content

Commit

Permalink
fix an issue in which level 1 does not immediately unlock
Browse files Browse the repository at this point in the history
This happened when the cursor is moved back to level 0 before navigating to
the subpage of level 1. The selector for rebuilding questions was too
restrictive, so that the level 1 questions would never rebuild (and thus
not become visible) in this case.

A workaround for this problem in 1.1.2 is to solve level 0 again, or to
change the theme or reset the progress.
  • Loading branch information
mwageringel committed Aug 11, 2022
1 parent 135adbd commit 9f026a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## [Unreleased]
### Fixed
- an issue in which level 1 did not unlock
(Workaround for version 1.1.2: Solve the very first question again or change the theme.)

## [1.1.2] - 2022-07-22
### Added
Expand Down
13 changes: 10 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,18 @@ class ExamsScreen extends StatelessWidget {
padding: listPadding,
itemCount: Provider.of<Game>(context, listen: false).levels.length, // as number of levels is constant, not listening avoids unnecessary rebuilds
itemBuilder: (context, levelIdx) => Selector<Game, bool>(
selector: (context, game) => levelIdx == game.activeLevel && game.inExamScreen, // isActive
shouldRebuild: (bool oldIsActive, bool isActive) => oldIsActive || isActive,
builder: (_, isActive, child) { // we do not use the inner context since world changes (such as theme) would not trigger a rebuild
selector: (context, game) {
// Rendering exam questions is only relevant when in the exam screen.
// This deliberately covers a broad range of questions to avoid missing important rebuilds.
// Fortunately, Flutter only renders the questions that are visible on screen.
final isRelevant = game.inExamScreen;
return isRelevant;
},
shouldRebuild: (bool oldIsRelevant, bool newIsRelevant) => oldIsRelevant || newIsRelevant,
builder: (_, isRelevant, child) { // we do not use the inner context since world changes (such as theme) would not trigger a rebuild
final game = Provider.of<Game>(context, listen: false); // listening not needed, since selector already does
assert((levelIdx > 0) ^ game.levels[levelIdx].exercise.questions.isEmpty);
final isActive = levelIdx == game.activeLevel && game.inExamScreen;
final level = game.levels[levelIdx];
final label = 'Level $levelIdx';
final unlocked = levelIdx <= game.levelsUnlocked || debugUnlockAll;
Expand Down

0 comments on commit 9f026a5

Please sign in to comment.