configure method
Future<void>
configure({
- Widget? loader,
- Widget? logo,
- List<
BaseThemeConfig> ? themes, - String? initialThemeId,
- Map<
String, ToastStyleFactory> ? toastNotifications, - Map<
Type, dynamic> ? modelDecoders, - Map<
Type, dynamic> ? controllers, - Map<
Type, dynamic> ? apiDecoders, - Map<
Type, NyEvent> ? events, - Map<
String, dynamic> ? formCasts, - String? authKey,
- dynamic syncKeys,
- bool useErrorStack = false,
- ErrorStackLogLevel? errorStackLevel,
- Widget errorStackWidget()?,
- bool monitorAppUsage = false,
- bool showDateTimeInLogs = false,
- bool broadcastEvents = false,
- NyLogCallback? onLog,
- NyLocalizationConfig? localization,
Configure Nylo with all settings in a single call.
This method provides a cleaner way to initialize Nylo by consolidating all configuration options into a single method call.
Example:
await nylo.configure(
loader: DesignConfig.loader,
logo: DesignConfig.logo,
themes: appThemes,
initialThemeId: 'light_theme',
toastNotifications: ToastNotificationConfig.styles,
modelDecoders: modelDecoders,
controllers: controllers,
apiDecoders: apiDecoders,
authKey: StorageKeysConfig.auth,
syncKeys: StorageKeysConfig.syncedOnBoot,
useErrorStack: true,
monitorAppUsage: true,
localization: LocalizationConfig(
localeType: localeType,
languageCode: 'en',
assetsDirectory: 'lang/',
),
);
Implementation
Future<void> configure({
// UI
Widget? loader,
Widget? logo,
// Themes
List<BaseThemeConfig>? themes,
String? initialThemeId,
// Notifications
Map<String, ToastStyleFactory>? toastNotifications,
// Decoders & Controllers
Map<Type, dynamic>? modelDecoders,
Map<Type, dynamic>? controllers,
Map<Type, dynamic>? apiDecoders,
// Events
Map<Type, NyEvent>? events,
Map<String, dynamic>? formCasts,
// Auth & Storage
String? authKey,
dynamic syncKeys,
// Features
bool useErrorStack = false,
ErrorStackLogLevel? errorStackLevel,
Widget Function(FlutterErrorDetails)? errorStackWidget,
bool monitorAppUsage = false,
bool showDateTimeInLogs = false,
bool broadcastEvents = false,
NyLogCallback? onLog,
// Localization
NyLocalizationConfig? localization,
}) async {
// Localization
if (localization != null) {
await NyLocalization.instance.init(
localeType: localization.localeType,
languageCode: localization.languageCode,
assetsDirectory: localization.assetsDirectory,
);
}
// UI
if (loader != null) addLoader(loader);
if (logo != null) addLogo(logo);
// Themes
if (themes != null) {
NyThemeManager.instance.registerThemes(
themes,
initialThemeId: initialThemeId,
);
}
// Notifications
if (toastNotifications != null) {
addToastNotifications(toastNotifications);
}
// Decoders & Controllers
if (modelDecoders != null) addModelDecoders(modelDecoders);
if (controllers != null) addControllers(controllers);
if (apiDecoders != null) addApiDecoders(apiDecoders);
// Events
if (events != null) addEvents(events);
if (formCasts != null) addFormCasts(formCasts);
// Auth & Storage
if (authKey != null) addAuthKey(authKey);
if (syncKeys != null) await this.syncKeys(syncKeys);
// Features
if (useErrorStack) {
this.useErrorStack(
level: errorStackLevel ?? ErrorStackLogLevel.verbose,
errorWidget: errorStackWidget,
);
// Auto-wire NyLogger to DevPanelStore
NyLogger.onLog = (entry) {
// Forward to DevPanelStore
switch (entry.type) {
case 'debug':
DevPanelStore.instance.debug(entry.message);
break;
case 'info':
DevPanelStore.instance.info(entry.message);
break;
case 'error':
DevPanelStore.instance.error(entry.message);
break;
case 'warning':
DevPanelStore.instance.warning(entry.message);
break;
default:
DevPanelStore.instance.debug(entry.message);
}
// Also call user's custom callback if provided
onLog?.call(entry);
};
} else if (onLog != null) {
// No ErrorStack, just use custom callback
NyLogger.onLog = onLog;
}
if (monitorAppUsage) this.monitorAppUsage();
if (showDateTimeInLogs) this.showDateTimeInLogs();
if (broadcastEvents) this.broadcastEvents(true);
}