We have a data repository in the backend which is hooked up to a realtime supabase table. Everytime there are certain changes we are listening for, the data repository is notifying our Cubit of the changes:
<code>/// Stream controller for notifying cubit about data changes.
final StreamController<void> _dataChangeController =
StreamController<void>.broadcast();
Stream<void> get onDataChanged => _dataChangeController.stream;
</code>
<code>/// Stream controller for notifying cubit about data changes.
final StreamController<void> _dataChangeController =
StreamController<void>.broadcast();
Stream<void> get onDataChanged => _dataChangeController.stream;
</code>
/// Stream controller for notifying cubit about data changes.
final StreamController<void> _dataChangeController =
StreamController<void>.broadcast();
Stream<void> get onDataChanged => _dataChangeController.stream;
And in the Cubit:
<code>// Initialize new data repository
await DataRepository.instance.init(locale);
_dataRepository = DataRepository.instance;
// Listen for data changes
_occupancySubscription =
_dataRepository!.onDataChanged.listen((_) => refreshSpots());
</code>
<code>// Initialize new data repository
await DataRepository.instance.init(locale);
_dataRepository = DataRepository.instance;
// Listen for data changes
_occupancySubscription =
_dataRepository!.onDataChanged.listen((_) => refreshSpots());
</code>
// Initialize new data repository
await DataRepository.instance.init(locale);
_dataRepository = DataRepository.instance;
// Listen for data changes
_occupancySubscription =
_dataRepository!.onDataChanged.listen((_) => refreshSpots());
I’m sorry if this is a dumb question, as this is surely bad practice, but then is it preferable to use a Bloc instead in this situation?
Thank you in advance, I just want to learn.