main function
void
main()
Implementation
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize Firebase
await Firebase.initializeApp();
// Initialize Hive
await Hive.initFlutter();
// Register Hive adapters (make sure adapters are generated)
Hive.registerAdapter(CropTaskAdapter());
Hive.registerAdapter(UserAdapter());
Hive.registerAdapter(UserRoleAdapter());
Hive.registerAdapter(ProductAdapter());
Hive.registerAdapter(ProductTypeAdapter());
Hive.registerAdapter(ListingTypeAdapter());
Hive.registerAdapter(CropDataAdapter());
Hive.registerAdapter(WateringScheduleAdapter());
// Open Hive boxes
await Hive.openBox<CropTask>(HiveService.taskBoxName);
await Hive.openBox<User>(HiveService.userBoxName);
await Hive.openBox<Product>(HiveService.productBoxName);
await Hive.openBox<CropData>(HiveService.cropDataBoxName);
await Hive.openBox(HiveService.settingsBoxName);
// Optional: Migrate or update old tasks if needed
final taskBox = Hive.box<CropTask>(HiveService.taskBoxName);
for (var task in taskBox.values) {
await task.save();
}
// Initialize HiveService (loads predefined crops if empty)
final hiveService = HiveService();
await hiveService.initializeCropData();
// Initialize Notifications
final notificationService = NotificationService();
await notificationService.initialize();
await notificationService.scheduleTaskNotifications();
// Firebase Realtime Database reference
final databaseRef = FirebaseDatabase.instance.ref();
runApp(MyApp(
notificationService: notificationService,
databaseRef: databaseRef,
));
}