Initial draft
This commit is contained in:
37
lib/bloc/app_bloc.dart
Normal file
37
lib/bloc/app_bloc.dart
Normal file
@ -0,0 +1,37 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/bloc/app_events.dart';
|
||||
import 'package:hl_lieferservice/bloc/app_states.dart';
|
||||
import 'package:hl_lieferservice/repository/config.dart';
|
||||
|
||||
import '../services/erpframe.dart';
|
||||
|
||||
class AppBloc extends Bloc<AppEvents, AppState> {
|
||||
AppBloc() : super(AppInitial()) {
|
||||
on<AppLoadConfig>(_loadConfig);
|
||||
}
|
||||
|
||||
Future<void> _loadConfig(AppLoadConfig event, Emitter<AppState> emit) async {
|
||||
emit(AppConfigLoading());
|
||||
try {
|
||||
final repository = ConfigurationRepository(path: event.path);
|
||||
final configuration = LocalDocuFrameConfiguration.fromJson(
|
||||
json.decode(await rootBundle.loadString("assets/${event.path}")),
|
||||
);
|
||||
|
||||
repository.setDocuFrameConfiguration(configuration);
|
||||
|
||||
emit(
|
||||
AppConfigLoaded(config: await repository.getDocuFrameConfiguration()),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(
|
||||
AppConfigLoadingFailed(
|
||||
message: "Fehler beim Laden der Konfigurationsdatei.",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
lib/bloc/app_events.dart
Normal file
7
lib/bloc/app_events.dart
Normal file
@ -0,0 +1,7 @@
|
||||
abstract class AppEvents {}
|
||||
|
||||
class AppLoadConfig extends AppEvents {
|
||||
String path;
|
||||
|
||||
AppLoadConfig({required this.path});
|
||||
}
|
||||
16
lib/bloc/app_states.dart
Normal file
16
lib/bloc/app_states.dart
Normal file
@ -0,0 +1,16 @@
|
||||
import '../services/erpframe.dart';
|
||||
|
||||
abstract class AppState {}
|
||||
|
||||
class AppInitial extends AppState {}
|
||||
class AppConfigLoading extends AppState {}
|
||||
class AppConfigLoaded extends AppState {
|
||||
LocalDocuFrameConfiguration config;
|
||||
|
||||
AppConfigLoaded({required this.config});
|
||||
}
|
||||
class AppConfigLoadingFailed extends AppState {
|
||||
String message;
|
||||
|
||||
AppConfigLoadingFailed({required this.message});
|
||||
}
|
||||
Reference in New Issue
Block a user