import 'dart:async'; import 'package:gifunavi/model/destination.dart'; import 'package:gifunavi/utils/database_helper.dart'; class DatabaseService { // Private constructor DatabaseService._privateConstructor(); // Static instance static final DatabaseService _instance = DatabaseService._privateConstructor(); // Factory constructor to return the instance factory DatabaseService() { return _instance; } // StreamController for updates final StreamController> _dbUpdateController = StreamController>.broadcast(); // Getter for the stream Stream> get destinationUpdatesStream => _dbUpdateController.stream; // Method to fetch destinations Future> fetchDestinations() async { // Your database fetch logic here List destinations = await _fetchFromDb(); _dbUpdateController.add(destinations); return destinations; } // Method to update the database and emit an update through the stream Future updateDatabase() async { // Your update logic here // After updating, fetch the updated list and add it to the stream fetchDestinations(); } // Method to fetch data from the database (placeholder) Future> _fetchFromDb() async { // Simulate fetching data with a delay DatabaseHelper db = DatabaseHelper.instance; List destinations = await db.getDestinations(); return destinations; // Replace with your actual fetch operation } // Dispose method to close the stream controller void dispose() { _dbUpdateController.close(); } }