initializeController method

void initializeController(
  1. ZenController controller
)

Implementation

void initializeController(ZenController controller) {
  try {
    if (!controller.isInitialized) {
      controller.onInit();

      // Schedule onReady to be called after the current frame (if in widget context)
      // For pure DI tests, call onReady immediately
      try {
        WidgetsBinding.instance.addPostFrameCallback((_) {
          if (!controller.isDisposed) {
            controller.onReady();
          }
        });
      } catch (_) {
        // WidgetsBinding not initialized - we're in a pure unit test
        // Call onReady immediately
        if (!controller.isDisposed) {
          controller.onReady();
        }
      }
    }
  } catch (e, stack) {
    ZenLogger.logError(
        'Error initializing controller ${controller.runtimeType}', e, stack);
  }
}