Getting error on implementing Dismissible widget in flutter

I have implemented the Dismissible widget in flutter application to swipe and remove the the indexed item. When I Remove any item from the list I get the below error in the logs

ERROR

RangeError (index): Invalid value: Not in inclusive range 0..48: 49

This is the code which is implemented

CODE

        SingleChildScrollView(

          child: Column(
            mainAxisAlignment: MainAxisAlignment.end,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
            
              ListView.separated(
                separatorBuilder: (context, index){
                  return Divider();
                },
                controller: _scrollController,
                itemCount: noteItems,
                shrinkWrap: true,
                itemBuilder: (context, index) {
                  final item = firstdata[index];
                  String arr = firstdata[index]['created_at'];
                  var arr2 = arr.split('-');
                  var content = firstdata[index]['company_details']['logo_name'];
                  print('logo name check');
                  print(content);

                  return
                    Dismissible(
                    direction: DismissDirection.endToStart,
                    key: ObjectKey(item),
                    onDismissed: (direction) {

                      deleteSingleNotifications(userid.toString(),firstdata[index]['id']);
                      setState(() {
                        firstdata.removeAt(index);
                      });


                    },
                    background: Container(color: Colors.red, child: Center(child: Text("DELETE", style: TextStyle(fontSize:50, fontWeight: FontWeight.bold),)),)
                    ,

                    child: Padding(

                      padding: const EdgeInsets.fromLTRB(8.0, 7.0, 8.0, 0.0),
                      child: Column(
                        children: <Widget>[


                          firstdata[index]['status'] == "0"?
                      Container(
                      color:Colors.grey.shade200,
                        child: ListTile(
                         

                          title:
                          Row(
                            children: [


                              Flexible(
                                child: firstdata[index]['title']!= null?AutoSizeText(
                                  firstdata[index]['title'],
                                  maxLines: 2,


                                  style: TextStyle(fontWeight: FontWeight.bold),) :Text(''),
                              ),
                            ],),



                        ),
                      )
                              :Container(
                            color: Colors.white,
                            child: ListTile(
                             
                             

                              title:
                              Row(
                                children: [


                                  Flexible(
                                    child: firstdata[index]['title']!= null?AutoSizeText(
                                      firstdata[index]['title'],
                                      maxLines: 2,


                                      style: TextStyle(fontWeight: FontWeight.bold),) :Text(''),
                                  ),

                                ],),



                            ),
                          ),
              ],
                      ),
                    ),
                  );

                },

              ),
            ],
          ),
        )

And when I tap on any item after removing a list item I get the below error.

ERROR

The method '+' was called on null. Receiver: null

How should I resolve this kind of issue?



Read more here: https://stackoverflow.com/questions/64402431/getting-error-on-implementing-dismissible-widget-in-flutter

Content Attribution

This content was originally published by Vicky Singh at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: