onInit method

void onInit()

Initializes the widget.

This method sets up initial configuration, routes, and observers for the widget.

Implementation

void onInit() {
  if (config.getPages == null && config.home == null) {
    throw Exception("You need add pages or home");
  }

  if (config.routerDelegate == null) {
    final GetDelegate newDelegate = GetDelegate.createDelegate(
      pages: config.getPages ??
          <GetPage<T>>[
            GetPage<T>(
              name: cleanRouteName("/${config.home.runtimeType}"),
              page: () => config.home!,
            ),
          ],
      notFoundRoute: config.unknownRoute,
      navigatorKey: config.navigatorKey,
      navigatorObservers: (config.navigatorObservers == null
          ? <NavigatorObserver>[
              GetObserver(config.routingCallback, Get.routing),
            ]
          : <NavigatorObserver>[
              GetObserver(config.routingCallback, config.routing),
              ...config.navigatorObservers!,
            ]),
    );
    config = config.copyWith(routerDelegate: newDelegate);
  }

  if (config.routeInformationParser == null) {
    final GetInformationParser<T> newRouteInformationParser =
        GetInformationParser<T>.createInformationParser(
      initialRoute: config.initialRoute ??
          config.getPages?.first.name ??
          cleanRouteName("/${config.home.runtimeType}"),
    );

    config =
        config.copyWith(routeInformationParser: newRouteInformationParser);
  }

  if (config.locale != null) {
    Get.locale = config.locale;
  }

  if (config.fallbackLocale != null) {
    Get.fallbackLocale = config.fallbackLocale;
  }

  if (config.translations != null) {
    Get.addTranslations(config.translations!.keys);
  } else if (config.translationsKeys != null) {
    Get.addTranslations(config.translationsKeys!);
  }

  Get.smartManagement = config.smartManagement;
  config.onInit?.call();

  Get.isLogEnable = config.enableLog ?? kDebugMode;
  Get.log = config.logWriterCallback ?? defaultLogWriterCallback;

  if (config.defaultTransition == null) {
    config = config.copyWith(defaultTransition: getThemeTransition());
  }

  Future<void>(onReady);
}