参数类型 'Pattern' 不能赋值给参数类型 'String'?

The argument type 'Pattern' can't be assigned to the parameter type 'String'?

我刚开始进行身份验证,遇到了这个错误。

validator: (value) {
                          Pattern pattern =
                              r'^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)| (\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
                          RegExp regex = new RegExp(pattern);
                          if (!regex.hasMatch(value!))
                            return 'Enter a valid email';
                          else
                            return null;
                        },

从这里复制:https://medium.com/swlh/how-to-implement-autofill-in-your-flutter-app-b43bddab1a97

但修复了一个错误,必须向 (value!)) 添加空检查。这是一个类似的问题吗?

这里是参考,检查下面的代码

validator: (value) {
if (value != null || value.isNotEmpty) {
final RegExp regex =
  RegExp(r'^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)| (\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$');
  if (!regex.hasMatch(value!))
      return 'Enter a valid email';
  else
      return null;
} else {
  return 'Enter a valid email';
}},