showSingleTextInput static method

Future<String> showSingleTextInput({
  1. BuildContext? context,
  2. String title = 'Title',
  3. String message = '',
  4. String initialText = '',
  5. String hintText = '',
  6. String cancelLabelText = 'Cancel',
  7. String okLabelText = 'OK',
})

显示单个文本输入框弹窗

title 标题 message 内容 initialText 输入框初始值 hintText 提示文字 cancelLabelText 取消按钮文本 okLabelText 确认按钮文本

返回结果

返回用户输入的字符串,若取消返回空字符串

用法示例

final text = await PPAlert.showSingleTextInput(
  title: "反馈",
  hintText: "请输入内容",
);

Implementation

static Future<String> showSingleTextInput({
  BuildContext? context,
  String title = 'Title',
  String message = '',
  String initialText = '',
  String hintText = '',
  String cancelLabelText = 'Cancel',
  String okLabelText = 'OK',
}) async {
  final dialogContext = _resolveDialogContext(context);
  if (dialogContext == null) return '';

  final texts = await showTextInputDialog(
    context: dialogContext,
    title: title,
    message: message.isNotEmpty ? message : null,
    textFields: [
      DialogTextField(initialText: initialText, hintText: hintText),
    ],
  );
  // 返回结果:用户输入的内容,或空字符串(取消/关闭时)
  return texts != null && texts.isNotEmpty ? texts[0] : '';
}