isValidUrl method

bool isValidUrl([
  1. List<String?> protocols = const ['http', 'https', 'ftp']
])

check string is valid url

Implementation

bool isValidUrl([List<String?> protocols = const ['http', 'https', 'ftp']]) {
  var str = this;
  if (str == null || str.isEmpty) return false;
  var schemes = protocols.join('|');
  String pattern = r'(' +
      schemes +
      r')://[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:/~+#-]*[\w@?^=%&amp;/~+#-])?';
  RegExp regExp = RegExp(pattern);
  return regExp.hasMatch(str);
}