fix(bootstraper): invalid logic

This commit is contained in:
hdbg
2025-10-09 18:45:50 +02:00
parent d08174c79f
commit 85f06c3785
3 changed files with 25 additions and 34 deletions

View File

@@ -1,6 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'dart:isolate';
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
@@ -48,7 +46,7 @@ class BootstrapState with _$BootstrapState {
final StageController? controller; final StageController? controller;
StageFactory get currentStage => stages[currentStageIndex]; StageFactory get currentStage => stages[currentStageIndex];
bool get isCompleted => currentStageIndex > stages.length; bool get isCompleted => currentStageIndex >= stages.length;
BootstrapState(this.stages, {this.currentStageIndex = 0, this.controller}); BootstrapState(this.stages, {this.currentStageIndex = 0, this.controller});
} }
@@ -81,6 +79,7 @@ class BootstrapController extends Bloc<BootstrapEvent, BootstrapState> {
if (newState.isCompleted) { if (newState.isCompleted) {
talker.info("BootstrapController: All stages completed"); talker.info("BootstrapController: All stages completed");
add(const BootstrapEvent.finished());
} else if (await newState.currentStage.isCompleted) { } else if (await newState.currentStage.isCompleted) {
talker.info( talker.info(
"BootstrapController: Stage ${newState.currentStage.title} already completed, skipping", "BootstrapController: Stage ${newState.currentStage.title} already completed, skipping",
@@ -93,30 +92,28 @@ class BootstrapController extends Bloc<BootstrapEvent, BootstrapState> {
emit(newState); emit(newState);
} }
}); });
on<FinishedEvent>((event, emit) {
talker.info("BootstrapController: Bootstrap process finished");
});
} }
StageController launchCurrentStage(Stages stages, int index) { StageController launchCurrentStage(Stages stages, int index) {
final currentStage = stages[index]; final currentStage = stages[index];
final controller = StageController(title: currentStage.title); final controller = StageController(title: currentStage.title);
Isolate.run( currentStage
() => currentStage .start(controller)
.start(controller) .then((_) {
.then((_) { add(BootstrapEvent.stageCompleted());
talker.info( })
"BootstrapController: Stage ${currentStage.title} completed", .catchError((error) {
); talker.handle(
add(BootstrapEvent.stageCompleted()); error,
}) null,
.catchError((error) { "BootstrapController: Error in ${currentStage.title}",
talker.handle( );
error, addError(error);
null, });
"BootstrapController: Error in ${currentStage.title}",
);
addError(error);
}),
);
return controller; return controller;
} }
@@ -136,7 +133,7 @@ class BootstrapFooter extends StatelessWidget {
return Column( return Column(
children: [ children: [
Text( Text(
"${state.currentStage.title} ${controller.state.progress.toStringAsFixed(2)}%", "${state.currentStage.title} ${(controller.state.progress * 100).toStringAsFixed(2)}%",
), ),
CircularProgressIndicator.adaptive( CircularProgressIndicator.adaptive(
value: controller.state.progress, value: controller.state.progress,
@@ -164,7 +161,6 @@ class Bootstrapper extends StatelessWidget {
create: (context) { create: (context) {
final controller = BootstrapController(BootstrapState(stages)); final controller = BootstrapController(BootstrapState(stages));
controller.add(const BootstrapEvent.start()); controller.add(const BootstrapEvent.start());
controller.launchCurrentStage(stages, 0);
return controller; return controller;
}, },
child: BlocListener<BootstrapController, BootstrapState>( child: BlocListener<BootstrapController, BootstrapState>(

View File

@@ -4,8 +4,8 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:rive/rive.dart'; import 'package:rive/rive.dart';
enum LoaderFlavour { enum LoaderFlavour {
small(filepath: 'assets/loaders/small_loaders/small_loader.riv'), small(filepath: 'assets/animations/loaders/small_loader.riv'),
big(filepath: 'assets/loaders/big_loaders/big_logo_splash.riv'); big(filepath: 'assets/animations/big_loaders/big_logo_splash.riv');
const LoaderFlavour({required this.filepath}); const LoaderFlavour({required this.filepath});
@@ -39,14 +39,9 @@ class Loader extends HookWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final animFile = useMemoized( final animFile = useMemoized(
() => () => FileLoader.fromAsset(flavour.filepath, riveFactory: Factory.rive),
FileLoader.fromAsset(flavour.filepath, riveFactory: Factory.flutter),
); );
useEffect(() {
return animFile.dispose;
}, [animFile]);
return RiveWidgetBuilder( return RiveWidgetBuilder(
fileLoader: animFile, fileLoader: animFile,
builder: (context, state) { builder: (context, state) {

View File

@@ -1,6 +1,6 @@
name: markettakers name: markettakers
description: "MarketTakers library" description: "MarketTakers library"
version: 1.0.0 version: 1.0.1
publish_to: https://gitea.tailc58da6.ts.net/api/packages/MarketTakers/pub/ publish_to: https://gitea.tailc58da6.ts.net/api/packages/MarketTakers/pub/
repository: https://gitea.tailc58da6.ts.net/MarketTakers/markettakers-flutter repository: https://gitea.tailc58da6.ts.net/MarketTakers/markettakers-flutter
@@ -31,5 +31,5 @@ dev_dependencies:
flutter: flutter:
assets: assets:
- assets/animations/big_loaders/ - assets/animations/big_loaders/big_logo_splash.riv
- assets/animations/loaders/ - assets/animations/loaders/small_loader.riv