Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent flashcards from being opened if empty and fix flashcards tutorial #36

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FlashcardSetSettingsViewModel extends FutureViewModel {
final _dialogService = locator<DialogService>();
final _bottomSheetService = locator<BottomSheetService>();
final _sharedPreferencesService = locator<SharedPreferencesService>();
final _snackbarService = locator<SnackbarService>();

final FlashcardSet flashcardSet;

Expand Down Expand Up @@ -219,6 +220,14 @@ class FlashcardSetSettingsViewModel extends FutureViewModel {
}

void openFlashcardSet() {
if (flashcardSet.myDictionaryLists.isEmpty &&
flashcardSet.predefinedDictionaryLists.isEmpty) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
return;
}

_navigationService.navigateTo(
Routes.flashcardsView,
arguments: FlashcardsViewArguments(flashcardSet: flashcardSet),
Expand Down
19 changes: 13 additions & 6 deletions lib/ui/views/flashcards/flashcards_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FlashcardsView extends HookWidget {
if (animation != null) {
void handler(status) {
if (status == AnimationStatus.completed) {
_showTutorial(context, flipCardController);
_showTutorial(context, viewModel, flipCardController);
animation.removeStatusListener(handler);
}
}
Expand All @@ -57,7 +57,11 @@ class FlashcardsView extends HookWidget {
// Animation was not available, show tutorial after short delay
Future.delayed(
const Duration(milliseconds: 150),
() => _showTutorial(context, flipCardController),
() {
if (context.mounted) {
_showTutorial(context, viewModel, flipCardController);
}
},
);
}
}
Expand Down Expand Up @@ -196,16 +200,19 @@ class FlashcardsView extends HookWidget {

void _showTutorial(
BuildContext context,
FlashcardsViewModel viewModel,
FlipCardController flipCardController,
) {
TutorialCoachMark(
pulseEnable: false,
onSkip: () => false,
onFinish: () async {
await Future.delayed(const Duration(milliseconds: 100));
flipCardController.flip();
await Future.delayed(const Duration(milliseconds: 350));
flipCardController.flip();
if (viewModel.activeFlashcards.isNotEmpty) {
await Future.delayed(const Duration(milliseconds: 100));
flipCardController.flip();
await Future.delayed(const Duration(milliseconds: 350));
flipCardController.flip();
}
},
targets: [
TargetFocus(
Expand Down
17 changes: 17 additions & 0 deletions lib/ui/views/learning/learning_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class LearningViewModel extends FutureViewModel {
final _dictionaryService = locator<DictionaryService>();
final _navigationService = locator<NavigationService>();
final _dialogService = locator<DialogService>();
final _snackbarService = locator<SnackbarService>();

List<FlashcardSet>? _flashcardSets;
List<FlashcardSet>? get flashcardSets => _flashcardSets;
Expand Down Expand Up @@ -41,6 +42,14 @@ class LearningViewModel extends FutureViewModel {
}

void openFlashcardSet(FlashcardSet flashcardSet) {
if (flashcardSet.myDictionaryLists.isEmpty &&
flashcardSet.predefinedDictionaryLists.isEmpty) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
return;
}

_navigationService.navigateTo(
Routes.flashcardsView,
arguments: FlashcardsViewArguments(flashcardSet: flashcardSet),
Expand All @@ -54,6 +63,14 @@ class LearningViewModel extends FutureViewModel {
Future<void> selectFlashcardStartMode(FlashcardSet flashcardSet) async {
if (!flashcardSet.usingSpacedRepetition) return;

if (flashcardSet.myDictionaryLists.isEmpty &&
flashcardSet.predefinedDictionaryLists.isEmpty) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
return;
}

final response = await _dialogService.showCustomDialog(
variant: DialogType.flashcardStart,
barrierDismissible: true,
Expand Down