addTextInput method

void addTextInput({
  1. required String customId,
  2. required String label,
  3. TextInputStyle style = TextInputStyle.short,
  4. String? placeholder,
  5. String? value,
  6. int? minLength,
  7. int? maxLength,
  8. bool? isRequired,
  9. String? description,
})

Adds a text input field to the modal.

Creates a labeled text input component that allows users to enter text. The customId identifies this input when the modal is submitted.

Examples

Short text input (single-line)

modal.addTextInput(
  customId: 'username',
  label: 'Username',
  style: TextInputStyle.short,
  placeholder: 'Enter your username',
  minLength: 3,
  maxLength: 20,
  isRequired: true,
);

Paragraph input (multi-line)

modal.addTextInput(
  customId: 'feedback',
  label: 'Your Feedback',
  style: TextInputStyle.paragraph,
  placeholder: 'Tell us what you think...',
  minLength: 10,
  maxLength: 500,
  isRequired: true,
  description: 'Please be specific and constructive',
);

Pre-filled input (for editing)

modal.addTextInput(
  customId: 'bio',
  label: 'Biography',
  style: TextInputStyle.paragraph,
  value: currentUser.bio, // Pre-fill with existing value
  maxLength: 500,
  description: 'Update your profile bio',
);

Implementation

void addTextInput({
  required String customId,
  required String label,
  TextInputStyle style = TextInputStyle.short,
  String? placeholder,
  String? value,
  int? minLength,
  int? maxLength,
  bool? isRequired,
  String? description,
}) {
  final textInput = TextInput(
    customId,
    style: style,
    placeholder: placeholder,
    value: value,
    minLength: minLength,
    maxLength: maxLength,
    isRequired: isRequired,
  );

  _components.add(
    Label(
      label: label,
      component: textInput,
      description: description,
    ),
  );
}