I am making an app using the BLoC architecture using the flutter_bloc
package, but I need to get data from a database, which is asynchronous, meaning I can't initialize the BLoC with data from my database. Is there a way I can do this? My BLoC class text is
import 'package:countdown/database/utils.dart';
import 'package:countdown/events/countdown_event.dart';
import 'package:countdown/models/countdown.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class HomeBloc extends Bloc<CountdownEvent, List<Countdown>> {
@override
// TODO: implement initialState
List<Countdown> get initialState => DatabaseUtils.getCountdowns();
@override
Stream<List<Countdown>> mapEventToState(CountdownEvent event) {
}
}
I know this is very similar to This Question, but that question's answers don't have any code snippets which would be very helpful.