I havea bug where my code cant be build because this errorr can someone look my code here the code
Text(
"Login",
style: Theme.of(context).textTheme.headline2,
),
SizedBox(height: 20,),
new TextFormField(
keyboardType: TextInputType.emailAddress,
validator: (input) => !input.contains("@")
? "Email id Should be Valid"
: null,
)
],
),
),
),
it show error message "The method 'contains' can't be unconditionally invoked because the receiver can be 'null' try making the call conditional (using '?.' or adding a null check to target
can someone please fix my bug thanks before
You need to use:
TextFormField(
keyboardType: TextInputType.emailAddress,
validator: (input) => !(input?.contains("@") ?? false)
? "Email id Should be Valid"
: null,
)
As per the official documentationFormFieldValidator , the validator parameter is an optional String. So you need to convert that to non-nullable String first.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.