main function
The main entry point for the Portfolio application.
This function executes the following startup sequence:
- Framework Initialization: Ensures WidgetsFlutterBinding is ready.
- Platform Configuration: Sets up the databaseFactory specifically for Web environments using FFI.
- Dependency Injection: Initializes global state using MultiProvider.
- Note: CategoryProvider is reactive and depends on ProfileProvider to reload data whenever the user's specialty changes.
- 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(),
),
);
}