74 lines
2.3 KiB
Dart
74 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
|
|
|
import '../bloc/operation_state.dart';
|
|
|
|
/// Listens to [OperationBloc] and shows:
|
|
/// - SnackBars for success and error messages.
|
|
/// - A blocking modal barrier with a spinner while a mutation is in flight,
|
|
/// so the user gets unambiguous "wait" feedback and cannot double-tap or
|
|
/// navigate away mid-request.
|
|
class OperationViewEnforcer extends StatelessWidget {
|
|
final Widget child;
|
|
|
|
const OperationViewEnforcer({super.key, required this.child});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocConsumer<OperationBloc, OperationState>(
|
|
listener: (context, state) {
|
|
if (state is OperationFinished && state.message != null) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(state.message!)),
|
|
);
|
|
}
|
|
|
|
if (state is OperationFailed) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(state.message)),
|
|
);
|
|
}
|
|
},
|
|
builder: (context, state) {
|
|
final isInProgress = state is OperationInProgress;
|
|
final progressMessage =
|
|
isInProgress ? state.message : null;
|
|
|
|
return Stack(
|
|
children: [
|
|
child,
|
|
if (isInProgress)
|
|
PopScope(
|
|
canPop: false,
|
|
child: Stack(
|
|
children: [
|
|
const ModalBarrier(
|
|
dismissible: false,
|
|
color: Colors.black54,
|
|
),
|
|
Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const CircularProgressIndicator(),
|
|
if (progressMessage != null) ...[
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
progressMessage,
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|