askUrl static method

Future<String> askUrl(
  1. String question, {
  2. String? defaultValue,
})

Ask for URL input with validation

Implementation

static Future<String> askUrl(String question, {String? defaultValue}) async {
  if (PromptEnvironment.useSimplePrompts) {
    return _askSimpleString(
      question,
      defaultValue: defaultValue,
      validator: _isUrl,
      validationMessage: 'Please enter a valid URL (http:// or https://)',
    );
  }

  try {
    final String result = Input(
      prompt: question,
      defaultValue: defaultValue ?? '',
      validator: (String value) {
        if (_isUrl(value)) return true;
        throw ValidationError(
          'Please enter a valid URL (http:// or https://)',
        );
      },
    ).interact();
    return result;
  } on Object {
    return defaultValue ?? '';
  }
}