Skip to content

Instantly share code, notes, and snippets.

@zamahaka
Created November 27, 2019 13:53
Show Gist options
  • Save zamahaka/6571d1f934665e00f2462ae0a18c9822 to your computer and use it in GitHub Desktop.
Save zamahaka/6571d1f934665e00f2462ae0a18c9822 to your computer and use it in GitHub Desktop.
import 'package:speakee_flutter/base/speakee_view.dart';
import 'package:speakee_flutter/lessons/sentence_building/widgets/word_card_model.dart';
import 'build_a_word_contract.dart';
class BuildAWordPresenterImpl extends BuildAWordPresenter {
BuildAWordView _view;
List<String> choices;
List<String> userChoices;
BuildAWordPresenterImpl(SpeakeeView view, List<String> choices) {
this._view = view;
}
@override
void checkWordCard(int index, WordCardModel wordCard) {
if (index == wordCard.wordIndex) {
_view.addWordCard(wordCard.positionInSentence);
} else {
_view.showShakeAnimation();
}
}
void onChiceSelected(
Choice choice,
) {
var correctIndex = choices.indexOf(choice);
var currentIndex = userChoices.length;
if (correctIndex == currentIndex) {
userChoices.add(choice.choice);
_view.showInput(userChoices);
_view.showChoices(
active: choices.map((choice) {
Choice(choice: choice, isActive: !userChoices.contains(choice));
}).toList());
} else {
_view.showShakeAnimation();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment