url method Null safety

String? url(
  1. String? value,
  2. {String? message,
  3. List<String?> protocols = const ['http', 'https', 'ftp'],
  4. bool requireTld = true,
  5. bool requireProtocol = false,
  6. bool allowUnderscore = false,
  7. List<String> hostWhitelist = const [],
  8. List<String> hostBlacklist = const []}
)

Check if the value is a valid URL. This check is more elaborate than the simple check. it checks if the URL is valid and if it is, it checks if the protocol is as expected, if the top level domain if specified matches and if underscores are allowed or not In addition the check also checks if the port is valid and you can specify whitelisted and backlisted hosts.

Implementation

static String? url(String? value,
        {String? message,
        List<String?> protocols = const ['http', 'https', 'ftp'],
        bool requireTld = true,
        bool requireProtocol = false,
        bool allowUnderscore = false,
        List<String> hostWhitelist = const [],
        List<String> hostBlacklist = const []}) =>
    value == null ||
            value.isEmpty ||
            validations.isURL(value,
                protocols: protocols,
                requireTld: requireTld,
                requireProtocol: requireProtocol,
                allowUnderscore: allowUnderscore,
                hostWhitelist: hostWhitelist,
                hostBlacklist: hostBlacklist)
        ? null
        : message ?? 'Please enter a valid URL';