fixed overwrite on internal copy, DST drift in widget anchors, inline errors without controller and removed dead room lookup
This commit is contained in:
@@ -31,6 +31,7 @@ class AsyncActionButton extends StatelessWidget {
|
||||
errorBuilder: errorBuilder,
|
||||
onError: onError,
|
||||
onSuccess: onSuccess,
|
||||
showInlineError: showInlineError,
|
||||
builder: (context, busy, handler) {
|
||||
final lead = busy
|
||||
? AppProgressIndicator.small(
|
||||
@@ -38,13 +39,11 @@ class AsyncActionButton extends StatelessWidget {
|
||||
)
|
||||
: (icon == null ? null : Icon(icon));
|
||||
final content = lead == null ? child : _leadingLabel(lead, child);
|
||||
final button = ElevatedButton(
|
||||
return ElevatedButton(
|
||||
onPressed: handler,
|
||||
style: style,
|
||||
child: content,
|
||||
);
|
||||
if (!showInlineError) return button;
|
||||
return _InlineErrorWrapper(controller: controller, child: button);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ class _AsyncMixin extends StatefulWidget {
|
||||
final AsyncErrorBuilder? errorBuilder;
|
||||
final void Function(String message)? onError;
|
||||
final VoidCallback? onSuccess;
|
||||
final bool showInlineError;
|
||||
final Widget Function(BuildContext context, bool busy, VoidCallback? handler)
|
||||
builder;
|
||||
|
||||
@@ -16,6 +17,7 @@ class _AsyncMixin extends StatefulWidget {
|
||||
this.errorBuilder,
|
||||
this.onError,
|
||||
this.onSuccess,
|
||||
this.showInlineError = false,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -73,27 +75,27 @@ class _AsyncMixinState extends State<_AsyncMixin> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final busy = _controller.busy;
|
||||
return widget.builder(
|
||||
final child = widget.builder(
|
||||
context,
|
||||
busy,
|
||||
busy || widget.onPressed == null ? null : _trigger,
|
||||
);
|
||||
if (!widget.showInlineError) return child;
|
||||
return _InlineErrorWrapper(controller: _controller, child: child);
|
||||
}
|
||||
}
|
||||
|
||||
class _InlineErrorWrapper extends StatelessWidget {
|
||||
final AsyncActionController? controller;
|
||||
final AsyncActionController controller;
|
||||
final Widget child;
|
||||
const _InlineErrorWrapper({required this.controller, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = controller;
|
||||
if (c == null) return child;
|
||||
return AnimatedBuilder(
|
||||
animation: c,
|
||||
animation: controller,
|
||||
builder: (context, _) {
|
||||
final err = c.error;
|
||||
final err = controller.error;
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
|
||||
@@ -27,6 +27,7 @@ class AsyncTextButton extends StatelessWidget {
|
||||
errorBuilder: errorBuilder,
|
||||
onError: onError,
|
||||
onSuccess: onSuccess,
|
||||
showInlineError: showInlineError,
|
||||
builder: (context, busy, handler) {
|
||||
final content = busy
|
||||
? _leadingLabel(
|
||||
@@ -37,8 +38,7 @@ class AsyncTextButton extends StatelessWidget {
|
||||
)
|
||||
: child;
|
||||
final button = TextButton(onPressed: handler, child: content);
|
||||
if (!showInlineError) return button;
|
||||
return _InlineErrorWrapper(controller: controller, child: button);
|
||||
return button;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ class ConfirmDialog extends StatelessWidget {
|
||||
/// Label of the cancel button. Set to `null` for a single-button dialog
|
||||
/// (only the confirm action is rendered).
|
||||
final String? cancelButton;
|
||||
|
||||
/// Optional: without [onConfirm]/[onConfirmAsync] the dialog only reports
|
||||
/// the decision via [ask].
|
||||
final void Function()? onConfirm;
|
||||
final AsyncActionCallback? onConfirmAsync;
|
||||
final AsyncErrorBuilder? errorBuilder;
|
||||
@@ -27,15 +30,17 @@ class ConfirmDialog extends StatelessWidget {
|
||||
this.onConfirm,
|
||||
this.onConfirmAsync,
|
||||
this.errorBuilder,
|
||||
}) : assert(
|
||||
onConfirm != null || onConfirmAsync != null,
|
||||
'ConfirmDialog requires either onConfirm or onConfirmAsync',
|
||||
);
|
||||
});
|
||||
|
||||
void asDialog(BuildContext context) {
|
||||
showDialog(context: context, builder: build);
|
||||
}
|
||||
|
||||
/// Resolves to true once confirmed – with [onConfirmAsync] only after it
|
||||
/// succeeded.
|
||||
Future<bool> ask(BuildContext context) async =>
|
||||
await showDialog<bool>(context: context, builder: build) ?? false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AlertDialog(
|
||||
icon: icon != null ? Icon(icon) : null,
|
||||
@@ -59,8 +64,8 @@ class ConfirmDialog extends StatelessWidget {
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Haptics.confirm();
|
||||
Navigator.of(context).pop();
|
||||
onConfirm!();
|
||||
Navigator.of(context).pop(true);
|
||||
onConfirm?.call();
|
||||
},
|
||||
child: Text(confirmButton),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user