onInit method

void onInit()

Implementation

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

    if (config.routerDelegate == null) {
      final newDelegate = GetDelegate.createDelegate(
        pages:
            config.getPages ??
            [
              GetPage(
                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 newRouteInformationParser =
          GetInformationParser.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(() => onReady());
}