main function

void main()

The main entry point for the Portfolio application.

This function executes the following startup sequence:

  1. Framework Initialization: Ensures WidgetsFlutterBinding is ready.
  2. Platform Configuration: Sets up the databaseFactory specifically for Web environments using FFI.
  3. Dependency Injection: Initializes global state using MultiProvider.
  4. UI Launch: Mounts the PortfolioApp widget tree.

Implementation

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  if (kIsWeb) {
    databaseFactory = databaseFactoryFfiWeb;
  }

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => PortfolioProvider()),
        ChangeNotifierProvider(create: (_) => ProfileProvider()),
        ChangeNotifierProvider(create: (_) => SettingsProvider()),

        ChangeNotifierProvider(create: (_) => PortfolioSearchProvider()),
        ChangeNotifierProxyProvider<ProfileProvider, CategoryProvider>(
          create: (context) => CategoryProvider(),
          update: (context, profileProvider, categoryProvider) {
            // This ensures that whenever the profile (and specialty) changes,
            // the categories are reloaded automatically.
            categoryProvider!.loadCategories(
              profileProvider.selectedSpecialty.name,
            );
            return categoryProvider;
          },
        ),
      ],
      child: const PortfolioApp(),
    ),
  );
}