prompt static method

TAlertController prompt(
  1. BuildContext context, {
  2. required String title,
  3. String? placeholder,
  4. String? initialValue,
  5. required ValueChanged<String> onConfirm,
  6. VoidCallback? onCancel,
  7. String confirmButtonText = 'Submit',
  8. String cancelButtonText = 'Cancel',
  9. Color? color,
  10. double? width = 500,
})

Shows a prompt dialog with a text field.

Implementation

static TAlertController prompt(
  BuildContext context, {
  required String title,
  String? placeholder,
  String? initialValue,
  required ValueChanged<String> onConfirm,
  VoidCallback? onCancel,
  String confirmButtonText = 'Submit',
  String cancelButtonText = 'Cancel',
  Color? color,
  double? width = 500,
}) {
  final controller = TextEditingController(text: initialValue);

  return show(
    context,
    color: color ?? context.theme.info,
    width: width,
    theme: context.theme.alertTheme.copyWith(contentPadding: EdgeInsets.symmetric(vertical: 20, horizontal: 12)),
    text: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      spacing: 10,
      children: [
        Text(
          title,
          style: TextStyle(fontSize: 18, fontWeight: FontWeight.w400, color: context.colors.onSurfaceVariant),
        ),
        TTextField(
          labelPosition: TLabelPosition.aboveField,
          clearable: true,
          textController: controller,
          placeholder: placeholder ?? 'Enter value...',
          autoFocus: true,
        )
      ],
    ),
    confirmButton: AlertButton(
      text: confirmButtonText,
      onClick: () {
        onConfirm(controller.text);
        controller.dispose();
      },
    ),
    closeButton: AlertButton(
      text: cancelButtonText,
      onClick: () {
        onCancel?.call();
        controller.dispose();
      },
    ),
  );
}