Initial draft
This commit is contained in:
137
lib/widget/app.dart
Normal file
137
lib/widget/app.dart
Normal file
@ -0,0 +1,137 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/bloc/app_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/presentation/login_enforcer.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/presentation/car_management_page.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/repository/delivery_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/repository/note_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/service/notes_service.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/repository/tour_repository.dart';
|
||||
import 'package:hl_lieferservice/repository/user_repository.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/presentation/operation_view_enforcer.dart';
|
||||
|
||||
import 'package:hl_lieferservice/bloc/app_states.dart';
|
||||
import '../feature/delivery/overview/service/delivery_info_service.dart';
|
||||
import 'home/bloc/navigation_state.dart';
|
||||
import 'home/presentation/home.dart';
|
||||
|
||||
class DeliveryApp extends StatefulWidget {
|
||||
const DeliveryApp({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _DeliveryAppState();
|
||||
}
|
||||
|
||||
class _DeliveryAppState extends State<DeliveryApp> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AppBloc, AppState>(
|
||||
builder: (context, state) {
|
||||
if (state is AppConfigLoaded) {
|
||||
final currentAppState = state;
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(create: (context) => NavigationBloc()),
|
||||
BlocProvider(create: (context) => OperationBloc()),
|
||||
BlocProvider(
|
||||
create:
|
||||
(context) => AuthBloc(
|
||||
repository: UserRepository(),
|
||||
operationBloc: context.read<OperationBloc>(),
|
||||
),
|
||||
),
|
||||
BlocProvider(
|
||||
create:
|
||||
(context) => TourBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
deliveryRepository: TourRepository(
|
||||
service: DeliveryInfoService(
|
||||
config: currentAppState.config,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
BlocProvider(
|
||||
create:
|
||||
(context) => NoteBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
repository: NoteRepository(
|
||||
service: NoteService(config: currentAppState.config),
|
||||
),
|
||||
),
|
||||
),
|
||||
BlocProvider(
|
||||
create:
|
||||
(context) => DeliveryBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
repository: DeliveryRepository(
|
||||
service: DeliveryInfoService(
|
||||
config: currentAppState.config,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
home: OperationViewEnforcer(
|
||||
child: BlocBuilder<AppBloc, AppState>(
|
||||
builder: (context, state) {
|
||||
if (state is AppConfigLoading) {
|
||||
return Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AppConfigLoadingFailed) {
|
||||
return Scaffold(body: Center(child: Text(state.message)));
|
||||
}
|
||||
|
||||
if (state is AppConfigLoaded) {
|
||||
return BlocConsumer<NavigationBloc, NavigationState>(
|
||||
listener: (context, state) {
|
||||
if (state is NavigateToRoute) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
state.routeName,
|
||||
arguments: state.arguments,
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (BuildContext context, NavigationState state) {
|
||||
return LoginEnforcer(child: Home());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
routes: {"/cars": (context) => CarManagementPage()},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is AppConfigLoadingFailed) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(child: Text("Fehler beim Laden der Konfiguration")),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(child: const CircularProgressIndicator()),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user