initState method

  1. @override
void initState()
override

Called when this object is inserted into the tree.

The framework will call this method exactly once for each State object it creates.

Override this method to perform initialization that depends on the location at which this object was inserted into the tree (i.e., context) or on the widget used to configure this object (i.e., widget).

If a State's build method depends on an object that can itself change state, for example a ChangeNotifier or Stream, or some other object to which one can subscribe to receive notifications, then be sure to subscribe and unsubscribe properly in initState, didUpdateWidget, and dispose:

  • In initState, subscribe to the object.
  • In didUpdateWidget unsubscribe from the old object and subscribe to the new one if the updated widget configuration requires replacing the object.
  • In dispose, unsubscribe from the object.

You should not use BuildContext.dependOnInheritedWidgetOfExactType from this method. However, didChangeDependencies will be called immediately following this method, and BuildContext.dependOnInheritedWidgetOfExactType can be used there.

Implementations of this method should start with a call to the inherited method, as in super.initState().

Implementation

@override
void initState() {
  super.initState();

  // Initialize animation controllers - Animation schneller machen
  _stepAnimationController = AnimationController(
    duration: const Duration(milliseconds: 400), // Reduziert von 800ms auf 400ms
    vsync: this,
  );

  _chapterAnimationController = AnimationController(
    duration: const Duration(milliseconds: 600), // Reduziert von 1200ms auf 600ms
    vsync: this,
  );

  _stepAnimation = CurvedAnimation(
    parent: _stepAnimationController,
    curve: Curves.easeOutQuad, // Sanftere, schnellere Kurve statt easeInOutBack
  );

  _chapterAnimation = CurvedAnimation(
    parent: _chapterAnimationController,
    curve: Curves.elasticOut,
  );

  // Check if we arrived from completing an exercise
  WidgetsBinding.instance.addPostFrameCallback((_) {
    // Check if we have arguments from exercise completion
    if (Get.arguments != null &&
        Get.arguments['exerciseCompleted'] == true &&
        Get.arguments['isFirstInTimeWindow'] == true) {
      // Advance step as this is the first exercise in the time window
      advanceStep();
    } else {
      // Regular initialization - load progress normally
      _loadProgressFromStatistics();
    }

    // After short delay, scroll to current chapter
    Future.delayed(const Duration(milliseconds: 300), () {
      if (currentStep > 0) {
        _scrollToCurrentChapter();
      }
    });
  });
}