showSingleTextInput static method

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

显示单个文本输入框弹窗

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

返回结果

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

用法示例

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

Implementation

static Future<String> showSingleTextInput({
  String title = 'Title',
  String message = '',
  String initialText = '',
  String hintText = '',
  String cancelLabelText = 'Cancel',
  String okLabelText = 'OK',
}) async {
  final texts = await showTextInputDialog(
    context: Get.context!,
    title: title,
    message: message.isNotEmpty ? message : null,
    textFields: [
      DialogTextField(initialText: initialText, hintText: hintText),
    ],
  );
  // 返回结果:用户输入的内容,或空字符串(取消/关闭时)
  return texts != null && texts.isNotEmpty ? texts[0] : '';
}