This commit is contained in:
Dennis Nemec
2026-04-28 13:03:09 +02:00
parent de8668c11a
commit 2470299a10
53 changed files with 2409 additions and 1433 deletions

View File

@ -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),
),
),
);
}
}
}