Null check operator used on a null value: The relevant error-causing widget was CustomBottomBar

9.7k views Asked by At

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

2

There are 2 answers

0
Danusha Malshan On

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

1
Novice Coder On

You are getting this error because you are using a null check operator "!" on a variable that is already null. The solution is to properly initialize those variables or to avoid calling them when they're not initialized. Search for parts of code where you have added "!" operator and see if those variables are properly initialized or not. If you want more help, please edit your question to include the entire code where you're facing this error.