fix(bootstraper): invalid place to dispatch onCompleted
This commit is contained in:
@@ -55,11 +55,11 @@ class BootstrapState with _$BootstrapState {
|
||||
sealed class BootstrapEvent with _$BootstrapEvent {
|
||||
const factory BootstrapEvent.start() = StartEvent;
|
||||
const factory BootstrapEvent.stageCompleted() = StageCompletedEvent;
|
||||
const factory BootstrapEvent.finished() = FinishedEvent;
|
||||
}
|
||||
|
||||
class BootstrapController extends Bloc<BootstrapEvent, BootstrapState> {
|
||||
BootstrapController(super.initialState) {
|
||||
final Completer<void> completer;
|
||||
BootstrapController(super.initialState, this.completer) {
|
||||
assert(state.stages.isNotEmpty, "Stages list cannot be empty");
|
||||
|
||||
on<StartEvent>((event, emit) {
|
||||
@@ -79,7 +79,7 @@ class BootstrapController extends Bloc<BootstrapEvent, BootstrapState> {
|
||||
|
||||
if (newState.isCompleted) {
|
||||
talker.info("BootstrapController: All stages completed");
|
||||
add(const BootstrapEvent.finished());
|
||||
completer.complete();
|
||||
} else if (await newState.currentStage.isCompleted) {
|
||||
talker.info(
|
||||
"BootstrapController: Stage ${newState.currentStage.title} already completed, skipping",
|
||||
@@ -159,7 +159,10 @@ class Bootstrapper extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) {
|
||||
final controller = BootstrapController(BootstrapState(stages));
|
||||
final controller = BootstrapController(
|
||||
BootstrapState(stages),
|
||||
onCompleted,
|
||||
);
|
||||
controller.add(const BootstrapEvent.start());
|
||||
return controller;
|
||||
},
|
||||
@@ -175,9 +178,10 @@ class Bootstrapper extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 3,
|
||||
flex: 2,
|
||||
child: Center(child: Loader.playing(flavour: LoaderFlavour.big)),
|
||||
),
|
||||
Flexible(flex: 1, child: Container()),
|
||||
Flexible(flex: 1, child: BootstrapFooter()),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user