BIG FAT
This commit is contained in:
@ -4,7 +4,13 @@ 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/authentication/service/userinfo.dart';
|
||||
import 'package:hl_lieferservice/feature/car_selection/bloc/bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/car_selection/presentation/car_selection_enforcer.dart';
|
||||
import 'package:hl_lieferservice/feature/car_selection/repository/car_selection_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/bloc/cars_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/presentation/car_management_page.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/repository/cars_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/service/cars_service.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/repository/tour_repository.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart';
|
||||
@ -46,11 +52,23 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
create:
|
||||
(context) => TourBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
authBloc: context.read<AuthBloc>(),
|
||||
tourRepository: TourRepository(
|
||||
service: TourService(),
|
||||
),
|
||||
),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) =>
|
||||
CarSelectBloc(repository: CarSelectionRepository()),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => CarsBloc(
|
||||
repository: CarsRepository(service: CarService()),
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
authBloc: context.read<AuthBloc>(),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
home: OperationViewEnforcer(
|
||||
@ -67,7 +85,9 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
}
|
||||
|
||||
if (state is AppConfigLoaded) {
|
||||
return LoginEnforcer(child: Home());
|
||||
return LoginEnforcer(
|
||||
child: CarSelectionEnforcer(child: Home()),
|
||||
);
|
||||
}
|
||||
|
||||
return Container();
|
||||
|
||||
@ -7,15 +7,12 @@ import 'package:hl_lieferservice/feature/delivery/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_overview_page.dart';
|
||||
import 'package:hl_lieferservice/feature/scan/presentation/scan_page.dart';
|
||||
import 'package:hl_lieferservice/widget/app_bar.dart';
|
||||
import 'package:hl_lieferservice/feature/car_selection/presentation/selected_car_bar.dart';
|
||||
import 'package:hl_lieferservice/feature/settings/presentation/settings_page.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_state.dart';
|
||||
import 'package:hl_lieferservice/widget/navigation_bar/presentation/navigation_bar.dart';
|
||||
|
||||
import '../../../feature/cars/bloc/cars_bloc.dart';
|
||||
import '../../../feature/cars/repository/cars_repository.dart';
|
||||
import '../../../feature/cars/service/cars_service.dart';
|
||||
import '../../operations/bloc/operation_bloc.dart';
|
||||
|
||||
class Home extends StatefulWidget {
|
||||
const Home({super.key});
|
||||
@ -44,14 +41,11 @@ class _HomeState extends State<Home> {
|
||||
}
|
||||
|
||||
if (index == 2) {
|
||||
return BlocProvider(
|
||||
create:
|
||||
(context) => CarsBloc(
|
||||
repository: CarsRepository(service: CarService()),
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
),
|
||||
child: CarManagementPage(),
|
||||
);
|
||||
return CarManagementPage();
|
||||
}
|
||||
|
||||
if (index == 3) {
|
||||
return SettingsPage();
|
||||
}
|
||||
|
||||
return Container();
|
||||
@ -64,12 +58,14 @@ class _HomeState extends State<Home> {
|
||||
final currentState = state as NavigationInfo;
|
||||
|
||||
return Scaffold(
|
||||
appBar: PreferredSize(
|
||||
preferredSize: Size.fromHeight(kToolbarHeight),
|
||||
child: CustomAppBar(),
|
||||
),
|
||||
body: _buildPage(currentState.navigationIndex),
|
||||
bottomNavigationBar: AppNavigationBar(),
|
||||
bottomNavigationBar: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SelectedCarBar(),
|
||||
AppNavigationBar(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@ -32,6 +32,11 @@ class _AppNavigationBarState extends State<AppNavigationBar> {
|
||||
icon: Icon(Icons.local_shipping),
|
||||
label: "Fahrzeuge",
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.settings_outlined),
|
||||
selectedIcon: Icon(Icons.settings),
|
||||
label: "Einstellungen",
|
||||
),
|
||||
],
|
||||
onDestinationSelected: (int index) {
|
||||
context.read<NavigationBloc>().add(NavigateToIndex(index: index));
|
||||
|
||||
@ -4,28 +4,19 @@ import 'package:hl_lieferservice/widget/operations/bloc/operation_state.dart';
|
||||
|
||||
class OperationBloc extends Bloc<OperationEvent, OperationState> {
|
||||
OperationBloc() : super(OperationIdle()) {
|
||||
on<LoadOperation>(_loadOperation);
|
||||
on<FailOperation>(_failOperation);
|
||||
on<FinishOperation>(_finishOperation);
|
||||
}
|
||||
|
||||
Future<void> _loadOperation(LoadOperation event, Emitter<OperationState> emit) async {
|
||||
emit(OperationLoading());
|
||||
}
|
||||
|
||||
Future<void> _failOperation(FailOperation event, Emitter<OperationState> emit) async {
|
||||
emit(OperationFailed(message: event.message));
|
||||
|
||||
await Future.delayed(Duration(seconds: 5));
|
||||
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
emit(OperationIdle());
|
||||
}
|
||||
|
||||
Future<void> _finishOperation(FinishOperation event, Emitter<OperationState> emit) async {
|
||||
emit(OperationFinished(message: event.message));
|
||||
|
||||
await Future.delayed(Duration(seconds: 5));
|
||||
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
emit(OperationIdle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
abstract class OperationEvent {}
|
||||
|
||||
class LoadOperation extends OperationEvent {}
|
||||
|
||||
class FailOperation extends OperationEvent {
|
||||
String message;
|
||||
|
||||
@ -12,4 +10,4 @@ class FinishOperation extends OperationEvent {
|
||||
String? message;
|
||||
|
||||
FinishOperation({this.message});
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,6 @@ abstract class OperationState {}
|
||||
|
||||
class OperationIdle extends OperationState {}
|
||||
|
||||
class OperationLoading extends OperationState {}
|
||||
|
||||
class OperationFailed extends OperationState {
|
||||
String message;
|
||||
|
||||
@ -14,4 +12,4 @@ class OperationFinished extends OperationState {
|
||||
String? message;
|
||||
|
||||
OperationFinished({this.message});
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,47 +4,21 @@ import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
|
||||
import '../bloc/operation_state.dart';
|
||||
|
||||
/// OperationViewEnforcer
|
||||
///
|
||||
/// A view that encapsulates the functionality to react to asynchronous operations.
|
||||
/// It is capable of showing a loading indicator while an operation is ongoing and it shows
|
||||
/// a error message if the operation failed.
|
||||
class OperationViewEnforcer extends StatefulWidget {
|
||||
/// Listens to [OperationBloc] and shows SnackBars for success and error
|
||||
/// messages. Loading indicators are handled locally by each feature.
|
||||
class OperationViewEnforcer extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const OperationViewEnforcer({super.key, required this.child});
|
||||
@override
|
||||
State<OperationViewEnforcer> createState() => _OperationViewEnforcerState();
|
||||
}
|
||||
|
||||
class _OperationViewEnforcerState extends State<OperationViewEnforcer> {
|
||||
OverlayEntry? _overlayEntry;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_overlayEntry?.remove();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<OperationBloc, OperationState>(
|
||||
listener: (context, state) {
|
||||
if (state is OperationLoading) {
|
||||
if (_overlayEntry == null) {
|
||||
_overlayEntry = _createOverlayEntry(context);
|
||||
Overlay.of(context).insert(_overlayEntry!);
|
||||
}
|
||||
} else {
|
||||
_overlayEntry?.remove();
|
||||
_overlayEntry = null;
|
||||
}
|
||||
|
||||
if (state is OperationFinished) {
|
||||
if (state.message != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message!)),
|
||||
);
|
||||
}
|
||||
if (state is OperationFinished && state.message != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message!)),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is OperationFailed) {
|
||||
@ -53,20 +27,7 @@ class _OperationViewEnforcerState extends State<OperationViewEnforcer> {
|
||||
);
|
||||
}
|
||||
},
|
||||
child: widget.child,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
OverlayEntry _createOverlayEntry(BuildContext context) {
|
||||
return OverlayEntry(
|
||||
builder: (context) => DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
color: Color.fromRGBO(128, 128, 128, 0.8),
|
||||
),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user