Im new to Flutter. I got this error Null check operator used on a null value error. but I could not solve it. This is the place where the second exception "The relevant error-causing widget was Consumer" occurs:
@override
Widget build(BuildContext context) {
return Positioned(
bottom: ScreenUtil().setSp(74),
child: SizedBox(
width: ScreenUtil().setSp(67),
height: ScreenUtil().setSp(67),
child: Consumer<AnimationProvider>(
builder: (_, AnimationProvider animate, __) { // AnimationProvider
return FloatingActionButton(
backgroundColor: CustomColor.bluelight,
onPressed:
animate.flareAnimationCompleted
? () async => await _handleAnimation(context)
: () {},
child: buildFlareActor(animate));
},
),
),
);
}
the builder:
final Widget Function(
BuildContext context,
T value,
Widget? child,
) builder;
This is the debugger output:
════════ Exception caught by widgets library ══════════════════════════
Null check operator used on a null value The relevant error-causing widget was CustomBottomBar ═══════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ══════════════════════════
Null check operator used on a null value The relevant error-causing widget was Consumer AnimationProvider
═══════════════════════════════════════════════════════════════════════
Please help me. Thank you
you are getting this error because you are using the null check operator(!) on a null value. So get confirm your null check operator used variable is assign properly or not.
The Other Solution is you can initialize default value to the your variable
ex:-
int age=10; or you can use age ?? 20 instead of !age