null_check_operator_used_ona_null_value-flutter

Null check operator used on a null value

Hello developers, today I have resolved the “Null check operator used on a null value” error in a flutter, this error is common every flutter developer faces this error in app development, so in this article, I have resolved it as per the API responses level and widget bind level.

Cause ListView binding “Null check operator used on a null value”

categories – as per your API responses model array for help

   bool visible = false;
   
   
    Container(
                child:  categories.isEmpty
                    ? Center(
                        child: Padding(
                          padding: const EdgeInsets.all(10.0),
                          child: Column(
                            children: const [
                              Padding(
                                padding: EdgeInsets.all(8.0),
                                child: Icon(
                                  Icons.search_off,
                                  size: 80,
                                ),
                              ),
                              Padding(
                                padding: EdgeInsets.all(5.0),
                                child: Center(
                                  child: Text(
                                    'No results found',
                                    style: TextStyle(
                                        fontSize: 14,
                                        fontWeight: FontWeight.normal),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      )
                    : categories.isNotEmpty
                        ? ListView.builder(
                            scrollDirection: Axis.vertical,
                            shrinkWrap: true,
                            physics: const BouncingScrollPhysics(),
                            itemCount: categories.length,
                            itemBuilder: (BuildContext context, int index) {
                              
                              return ---> your listview design past hear 
                            })
                        : Center(
                            child: Visibility(
                              maintainSize: true,
                              maintainAnimation: true,
                              maintainState: true,
                              visible: visible,
                              child:
                                  const SpinKitThreeBounce(color: Colors.green),
                            ),
                          ),
              ),
              

For the help of the add SpinKitThreeBounce library for your project please visit

Cause TextFormField binding Null check operator used on a null value

For the help of the add List Create with the model library for your project please visit

   List<ItemStrick> _strickListCount = [];
 
 Widget _boxExit() {
    return Container(
      child: _strickListCount.isEmpty
          ? Center(
              child: Padding(
                padding: const EdgeInsets.all(10.0),
                child: Column(
                  children: const [
                    Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Icon(
                        Icons.search_off,
                        size: 80,
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.all(5.0),
                      child: Text(
                        'No results found',
                        style: TextStyle(
                            fontSize: 14, fontWeight: FontWeight.normal),
                      ),
                    ),
                  ],
                ),
              ),
            )
          : _strickListCount.isNotEmpty
              ? Container(
                  width: 50.0,
                  height: 29,
                  decoration: BoxDecoration(
                    color: ColorConstant.teal40020,
                  ),
                  margin:
                      const EdgeInsets.symmetric(vertical: 1, horizontal: 6),
                  alignment: Alignment.topCenter,
                  child: Padding(
                    padding: const EdgeInsets.all(4.0),
                    child: TextFormField(
                      
                      style: TextStyle(
                        color: ColorConstant.indigo800,
                        fontSize: getFontSize(
                          14,
                        ),
                        fontFamily: 'Roboto',
                        fontWeight: FontWeight.w500,
                      ),
                      textAlign: TextAlign.center,
                      keyboardType: TextInputType.number,
                      textInputAction: TextInputAction.next,
                      maxLength: 2,
                      decoration: const InputDecoration(
                        border: InputBorder.none,
                        errorStyle: TextStyle(height: 0),
                        counterText: '',
                         
                      ),
                      validator: (value) {
                        if (value == null || value.isEmpty) {
                          return 'Please enter no of days';
                        }
                        return null;
                      },
                    ),
                  ),
                )
             
              : Center(
                  child: const Visibility(
                    maintainSize: true,
                    maintainAnimation: true,
                    maintainState: true,
                    visible: true,
                    child: SpinKitThreeBounce(
                      color: Colors.green,
                      size: 30,
                    ),
                  ),
                ),
    );
  }

Cause label binding “Null check operator used on a null value”



 appBar: AppBar(
        toolbarHeight: 80, // default is 56
        toolbarOpacity: 0.5,
        
        title: Text(
          'Welcome, ' + vName.toString() ?? 'N/A',
          overflow: TextOverflow.ellipsis,
          textAlign: TextAlign.left,
          style: TextStyle(
            color: ColorConstant.whiteA703,
            fontSize: getFontSize(
              16,
            ),
            fontFamily: 'Poppins',
            fontWeight: FontWeight.w500,
          ),
        ),
        actions: [
          Padding(
            padding: const EdgeInsets.only(right: 8.0),
            child: Container(
              width: 30,
              child: Image.asset(
                'assets/images/user.png',
              ),
            ),
          ),
          // Icon(Icons.more_vert),
        ],
      
      ),
      
      
      //---example ---
      
      Text(vName.toString() ?? "String value is null on print the value of the label"),

I hope it was a useful article, please share and subscribe to my website/channel, You have enjoyed the most. Thanks for reading and if you have any questions or comments, See you soon. 

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *