Files
Client/lib/widget/async_actions/async_action_button.dart
T

50 lines
1.3 KiB
Dart

part of '../async_action_button.dart';
class AsyncActionButton extends StatelessWidget {
final AsyncActionCallback? onPressed;
final Widget child;
final IconData? icon;
final ButtonStyle? style;
final AsyncActionController? controller;
final AsyncErrorBuilder? errorBuilder;
final void Function(String message)? onError;
final VoidCallback? onSuccess;
final bool showInlineError;
const AsyncActionButton({
required this.onPressed,
required this.child,
this.icon,
this.style,
this.controller,
this.errorBuilder,
this.onError,
this.onSuccess,
this.showInlineError = true,
super.key,
});
@override
Widget build(BuildContext context) => _AsyncMixin(
onPressed: onPressed,
controller: controller,
errorBuilder: errorBuilder,
onError: onError,
onSuccess: onSuccess,
showInlineError: showInlineError,
builder: (context, busy, handler) {
final lead = busy
? AppProgressIndicator.small(
color: Theme.of(context).colorScheme.onPrimary,
)
: (icon == null ? null : Icon(icon));
final content = lead == null ? child : _leadingLabel(lead, child);
return ElevatedButton(
onPressed: handler,
style: style,
child: content,
);
},
);
}