StrokeOrderAnimationController constructor

StrokeOrderAnimationController(
  1. StrokeOrder _strokeOrder,
  2. TickerProvider tickerProvider, {
  3. double strokeAnimationSpeed = 1,
  4. double hintAnimationSpeed = 3,
  5. bool showStroke = true,
  6. bool showOutline = true,
  7. bool showBackground = false,
  8. bool showMedian = false,
  9. bool showUserStroke = false,
  10. bool highlightRadical = false,
  11. Color strokeColor = Colors.blue,
  12. Color outlineColor = Colors.black,
  13. Color backgroundColor = Colors.grey,
  14. Color medianColor = Colors.black,
  15. Color radicalColor = Colors.red,
  16. Color brushColor = Colors.black,
  17. double brushWidth = 8.0,
  18. double outlineWidth = 2.0,
  19. double medianWidth = 2.0,
  20. int hintAfterStrokes = 3,
  21. Color hintColor = Colors.lightBlueAccent,
  22. void onQuizCompleteCallback(
    1. QuizSummary
    )?,
  23. void onWrongStrokeCallback(
    1. int
    )?,
  24. void onCorrectStrokeCallback(
    1. int
    )?,
})

Creates a new StrokeOrderAnimationController.

A number of attributes can be set during initialization or via their respective setters:

  • Animation speed of stroke animations and hints in quiz mode (try 3 and adjust from there)
  • Whether to show/hide strokes
  • Whether to show/hide outlines
  • Whether to show/hide backgrounds for the strokes
  • Whether to show/hide medians
  • Whether to show/hide the correct strokes the user writes during a quiz
  • Whether to highlight radicals
  • Stroke color
  • Outline color
  • Background color (of the strokes, not the whole widget)
  • Median color
  • Radical color
  • Brush color in quiz mode
  • Brush thickness in quiz mode
  • Number of wrong strokes before showing a hint in quiz mode
  • Hint color in quiz mode

Don't forget to call dispose when the controller is no longer needed.

Implementation

StrokeOrderAnimationController(
  this._strokeOrder,
  TickerProvider tickerProvider, {
  double strokeAnimationSpeed = 1,
  double hintAnimationSpeed = 3,
  bool showStroke = true,
  bool showOutline = true,
  bool showBackground = false,
  bool showMedian = false,
  bool showUserStroke = false,
  bool highlightRadical = false,
  Color strokeColor = Colors.blue,
  Color outlineColor = Colors.black,
  Color backgroundColor = Colors.grey,
  Color medianColor = Colors.black,
  Color radicalColor = Colors.red,
  Color brushColor = Colors.black,
  double brushWidth = 8.0,
  double outlineWidth = 2.0,
  double medianWidth = 2.0,
  int hintAfterStrokes = 3,
  Color hintColor = Colors.lightBlueAccent,
  void Function(QuizSummary)? onQuizCompleteCallback,
  void Function(int)? onWrongStrokeCallback,
  void Function(int)? onCorrectStrokeCallback,
})  : _strokeColor = strokeColor,
      _showStroke = showStroke,
      _showOutline = showOutline,
      _showBackground = showBackground,
      _showMedian = showMedian,
      _showUserStroke = showUserStroke,
      _highlightRadical = highlightRadical,
      _outlineColor = outlineColor,
      _backgroundColor = backgroundColor,
      _medianColor = medianColor,
      _radicalColor = radicalColor,
      _brushColor = brushColor,
      _brushWidth = brushWidth,
      _outlineWidth = outlineWidth,
      _medianWidth = medianWidth,
      _hintAfterStrokes = hintAfterStrokes,
      _hintColor = hintColor,
      _strokeAnimationSpeed = strokeAnimationSpeed,
      _hintAnimationSpeed = hintAnimationSpeed,
      _strokeAnimationController = AnimationController(
        vsync: tickerProvider,
      ),
      _hintAnimationController = AnimationController(
        vsync: tickerProvider,
      ) {
  _strokeAnimationController.addStatusListener(_strokeCompleted);

  _hintAnimationController.addStatusListener((status) {
    if (status == AnimationStatus.completed) {
      _hintAnimationController.reset();
    }
  });

  _setCurrentStroke(0);
  _summary = QuizSummary(strokeOrder.nStrokes);

  if (onQuizCompleteCallback != null) {
    addOnQuizCompleteCallback(onQuizCompleteCallback);
  }
  if (onWrongStrokeCallback != null) {
    addOnWrongStrokeCallback(onWrongStrokeCallback);
  }
  if (onCorrectStrokeCallback != null) {
    addOnCorrectStrokeCallback(onCorrectStrokeCallback);
  }

  notifyListeners();
}