Skip to main content
CLI Setup: If you create a new Neo project using the Neo CLI, NeoInitializer will be fully configured for you inside main.dart with proper initialization timing and error handling.

Example

import 'package:flutter/widgets.dart';
import 'package:neo/neo.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'router/neo_router.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  NeoInitializer.initialize().then((_) {
    runApp(
      ProviderScope(
        child: MyApp(),
      ),
    );
  });
}

class MyApp extends ConsumerWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final neoRouter = ref.watch(routerProvider);

    return NeoApp(
      title: "My Neo App",
      routerConfig: neoRouter.config(),
    );
  }
}

What Gets Initialized

NeoInitializer sets up essential Neo framework components and systems required for your app to function properly. The initialization process automatically detects your platform and configures the appropriate features.

Methods

NeoInitializer.initialize()

Required Setup: You must call WidgetsFlutterBinding.ensureInitialized() before calling NeoInitializer.initialize(). This ensures Flutter’s binding is properly initialized before Neo’s systems start up.
Initializes all core Neo framework systems asynchronously. This method must be called before your app starts.

Return Value

returns
Future<void>
A Future that completes when all Neo systems have been successfully initialized. Always await this Future or use .then() before calling runApp().

Best Practices

  • Call Early: Always call NeoInitializer.initialize() in your main() function before runApp().
  • Ensure Binding: Call WidgetsFlutterBinding.ensureInitialized() before initialization to ensure Flutter is ready.
  • Await Completion: Always await the initialize call or use .then() to ensure initialization completes before your app starts.

Integration Notes

  • Platform Support: Initialization automatically detects the current platform and initializes only supported features. Unsupported features are safely skipped.
  • Logging: Initialization progress is automatically logged using NeoLogger, making it easy to track startup performance and debug initialization issues.
I