41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:finlytic_app/features/asset_detail/repositories/asset_repository.dart';
|
|
import 'asset_detail_event.dart';
|
|
import 'asset_detail_state.dart';
|
|
|
|
class AssetDetailBloc extends Bloc<AssetDetailEvent, AssetDetailState> {
|
|
final AssetRepository repository;
|
|
|
|
AssetDetailBloc({required this.repository}) : super(AssetDetailInitial()) {
|
|
on<LoadAssetData>(_onLoadAssetData);
|
|
on<ForceRefreshAssetData>(_onForceRefreshAssetData);
|
|
}
|
|
|
|
Future<void> _onLoadAssetData(LoadAssetData event, Emitter<AssetDetailState> emit) async {
|
|
emit(AssetDetailLoading());
|
|
try {
|
|
final results = await Future.wait([
|
|
repository.getFundamentalData(event.symbol),
|
|
repository.getTechnicalAnalysis(event.symbol),
|
|
]);
|
|
|
|
emit(AssetDetailLoaded(
|
|
fundamentalData: results[0] as dynamic,
|
|
technicalAnalysis: results[1] as dynamic,
|
|
));
|
|
} catch (e) {
|
|
emit(AssetDetailError("Fehler beim Laden der Asset-Daten."));
|
|
}
|
|
}
|
|
|
|
Future<void> _onForceRefreshAssetData(ForceRefreshAssetData event, Emitter<AssetDetailState> emit) async {
|
|
try {
|
|
await repository.forceRefreshFundamentalData(event.symbol);
|
|
// Optional: re-load after a delay, or rely on MQTT/SignalR to push the new data.
|
|
} catch (e) {
|
|
// ignore
|
|
}
|
|
}
|
|
}
|