Skip to content

Commit

Permalink
add questions shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
benhus8 committed Jan 10, 2025
1 parent 796d3fa commit 082e926
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mobile_app/lib/widgets/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class _MainPageState extends State<MainPage> {
bool _isTestMode = false;
int _currentPage = 0;
final int _questionsPerPage = 10;
late List<Question> _originalQuestions = [];
bool _isShuffled = false;

final ScrollController _scrollController = ScrollController();

Expand Down Expand Up @@ -53,6 +55,7 @@ class _MainPageState extends State<MainPage> {
final questions = await QuestionRepository().loadQuestions();
setState(() {
_allQuestions = questions;
_originalQuestions = List.from(questions);
_filterQuestions();
});
}
Expand All @@ -75,6 +78,21 @@ class _MainPageState extends State<MainPage> {
_saveStarredQuestions();
}

void _toggleShuffle() {
setState(() {
if (_isShuffled) {
_allQuestions = List.from(_originalQuestions);
} else {
_allQuestions.shuffle();
for (var question in _allQuestions) {
question.answers.shuffle();
}
}
_isShuffled = !_isShuffled;
_filterQuestions();
});
}

void _changeMode(String mode) {
_saveCurrentPage(_isTestMode ? "test" : "learning");
setState(() {
Expand Down Expand Up @@ -152,6 +170,12 @@ class _MainPageState extends State<MainPage> {
),
onPressed: _toggleStarred,
),
IconButton(
icon: Icon(
_isShuffled ? Icons.sort : Icons.shuffle,
),
onPressed: _toggleShuffle,
),
],
),
body: _filteredQuestions.isNotEmpty
Expand Down

0 comments on commit 082e926

Please sign in to comment.