onInit method

void onInit()

Implementation

void onInit() {
  // ignore: deprecated_member_use_from_same_package
  if (config.sintPages == null && config.home == null) {
    throw 'You need to provide sintPages (recommended) or home (deprecated). '
        'Use initialRoute + sintPages for string-based routing.';
  }

  if (config.routerDelegate == null) {
    final newDelegate = SintDelegate.createDelegate(
      // ignore: deprecated_member_use_from_same_package
      pages: config.sintPages ??
          [
            SintPage(
              // ignore: deprecated_member_use_from_same_package
              name: cleanRouteName("/${config.home.runtimeType}"),
              // ignore: deprecated_member_use_from_same_package
              page: () => config.home!,
            ),
          ],
      notFoundRoute: config.unknownRoute,
      navigatorKey: config.navigatorKey,
      navigatorObservers: (config.navigatorObservers == null
          ? <NavigatorObserver>[
              SintNavigationObserver(config.routingCallback, Sint.routing)
            ]
          : <NavigatorObserver>[
              SintNavigationObserver(config.routingCallback, config.routing),
              ...config.navigatorObservers!
            ]),
    );
    config = config.copyWith(routerDelegate: newDelegate);
  }

  if (config.routeInformationParser == null) {
    final newRouteInformationParser =
        SintInformationParser.createInformationParser(
      initialRoute: config.initialRoute ??
          config.sintPages?.first.name ??
          // ignore: deprecated_member_use_from_same_package
          cleanRouteName("/${config.home.runtimeType}"),
    );

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

  if (config.locale != null) Sint.locale = config.locale;

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

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

  // Build path translator for URL segment localization (web).
  if (config.translateEndpoints) {
    final delegate = config.routerDelegate as SintDelegate;
    final segments = PathTranslator.extractSegments(
      delegate.registeredRoutes,
    );
    Sint.pathTranslator = PathTranslator.build(
      translations: Sint.translations,
      routeSegments: segments,
    );
  }

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

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

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

  Future(() => onReady());
}