I get such an error in Flutter. What error I get is written in the title. I am also sending you my codes. I would appreciate your help.
class CustomizedTextFormField extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(15.0),
child: TextFormField(
enableSuggestions: isPassword! ? false : true,
autocorrect: isPassword! ? false : true,
obscureText: isPassword ?? true,
controller: myController,
cursorColor: cursorColor,
style: GoogleFonts.spaceMono(
color: textColor,
),
keyboardType: isPassword!? TextInputType.visiblePassword : TextInputType.emailAddress,
decoration: InputDecoration(
hintText: hintText,
hintStyle: GoogleFonts.spaceMono(
color: hintStyleTextColor,
),
labelText: lableText,
labelStyle: GoogleFonts.spaceMono(
color: lableStyleTextColor,
),
prefixIcon: SvgPicture.asset(
svgIcon,
fit: BoxFit.scaleDown,
height: 40,
width: 40,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: borderColor,
width: 1,
),
borderRadius: BorderRadius.circular(
10.0,
),
),
fillColor: textFormFieldFillColor,
filled: true,
suffixIcon: isPassword! ? IconButton(
icon: SvgPicture.asset(
iPasswordVisible,
height: 40,
width: 40,
fit: BoxFit.scaleDown,
),
onPressed: () {},
) : null,
),
),
);
}
}
I deleted the final parameters and threw them to you because the site does not allow too many lines of code.
I asked Chatgpt and Brad, and as an extra, I did what they said on the internet, but I didn’t get any results. I would appreciate your help.
2
Answers
You can use this code for your use case
This will remove your
null check operator used on a null value
error because we are not using anynullable
value in the code below.You are using the
!
operator in multiple places, but you haven’t ensured that the variables you are checking are non-null.To fix this issue, you need to ensure that you are using the
!
operator only on non-null variables.