title: How to update and delete a data in a list according to it's document id - flutter, firebase 2021
body: <p>I am trying to delete and update a list of details in flutter. For that i used <code>doc('document_id')</code> which was given as a solution in another stackoverflow question. I tried some another solutions given in stacker flow too. But nothing fork for me. But if I give a specific documentID I am able to delete that. Also how can I pass the selected data to update page too.</p>
  <pre><code>class addressProfile extends StatefulWidget {
  const addressProfile({Key? key}) : super(key: key);
  
  @override
  _addressProfileState createState() =&gt; _addressProfileState();
  }
  
  class _addressProfileState extends State&lt;addressProfile&gt; {
    var Default = 'unDefault';
  
  delete() async {
  try {
    FirebaseFirestore.instance
        .collection(&quot;address&quot;)
        .doc('document_id')
        .delete();
  } catch (e) {
    print(e);
  }
  }
  
  @override
  Widget build(BuildContext context) {
  return Scaffold(
    backgroundColor: Colors.grey.shade100,
    appBar: AppBar(
      centerTitle: true,
      backgroundColor: Theme.of(context).scaffoldBackgroundColor,
      title: Text(
        'My Addresses',
        style: TextStyle(color: Colors.black),
      ),
      leading: IconButton(
        icon: Icon(
          Icons.arrow_back_ios,
          color: Colors.black,
        ),
        onPressed: () {
          Navigator.of(context).pushNamed('/profilePage');
        },
      ),
    ),
    body: ListView(
      padding: EdgeInsets.all(16),
      children: [
        StreamBuilder&lt;QuerySnapshot&gt;(
            stream:
                FirebaseFirestore.instance.collection(&quot;address&quot;).snapshots(),
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                return Expanded(
                  child: SizedBox(
                    height: 700,
                    child: ListView.builder(
                      itemCount: snapshot.data!.docs.length,
                      itemBuilder: (context, index) {
                        QueryDocumentSnapshot x = snapshot.data!.docs[index];
                        return Container(
                          child: Card(
                            child: Padding(
                              padding: EdgeInsets.all(12),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    children: [
                                      Text(x['firstName']),
                                      Text(' '),
                                      Text(x['lastName']),
                                    ],
                                  ),
                                  Text(&quot;&quot;),
                                  Row(
                                    children: [
                                      Text(x['primaryPhone']),
                                      Text(&quot; / &quot;),
                                      Text(x['secondaryPhone']),
                                    ],
                                  ),
                                  Text(''),
                                  Row(
                                    children: [
                                      Text(x['address1']),
                                      Text(', '),
                                      Text(x['address2']),
                                      Text(', '),
                                      Text(x['city']),
                                      Text(', '),
                                      Text(x['region']),
                                    ],
                                  ),
                                  Divider(
                                    color: Colors.black,
                                  ),
                                  Row(
                                    children: [
                                      Container(
                                        child: Radio(
                                            value: 'default',
                                            groupValue: Default,
                                            onChanged: (String? val) {
                                              setState(() {
                                                if (val != null)
                                                  Default = val;
                                              });
                                            }),
                                      ),
                                      Container(
                                        child: Text(&quot;Default&quot;),
                                      ),
                                      Container(
                                        padding: EdgeInsets.only(left: 60),
                                        child: Align(
                                          child: ElevatedButton.icon(
                                            onPressed: () {
                                              if (snapshot.data!.docs.length &gt;
                                                  1) {
                                                delete();
                                                Fluttertoast.showToast(
                                                  msg:
                                                      &quot;Address deleted successfully&quot;,
                                                  toastLength:
                                                      Toast.LENGTH_SHORT,
                                                  gravity:
                                                      ToastGravity.BOTTOM,
                                                  textColor: Colors.black,
                                                  backgroundColor:
                                                      Colors.green.shade400,
                                                );
                                              } else {
                                                Fluttertoast.showToast(
                                                  msg:
                                                      &quot;Main address cannot be deleted&quot;,
                                                  toastLength:
                                                      Toast.LENGTH_SHORT,
                                                  gravity:
                                                      ToastGravity.BOTTOM,
                                                  textColor: Colors.black,
                                                  backgroundColor:
                                                      Colors.green.shade400,
                                                );
                                              }
                                            },
                                            label: Text('Delete'),
                                            style: ElevatedButton.styleFrom(
                                                fixedSize: Size(90, 20),
                                                primary: Colors.red.shade500,
                                                padding: EdgeInsets.symmetric(
                                                  horizontal: 5,
                                                ),
                                                shape: RoundedRectangleBorder(
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            10))),
                                            icon: Icon(
                                                Icons.delete_outline_sharp),
                                          ),
                                        ),
                                      ),
                                      Container(
                                        padding: EdgeInsets.only(left: 14),
                                        child: Align(
                                          child: ElevatedButton.icon(
                                            onPressed: () {
                                              Navigator.push(
                                                context,
                                                MaterialPageRoute(
                                                  builder: (builder) =&gt;
                                                      updateAddress(),
                                                ),
                                              );
                                            },
                                            label: Text('Update'),
                                            style: ElevatedButton.styleFrom(
                                                fixedSize: Size(90, 20),
                                                primary:
                                                    Colors.green.shade500,
                                                padding: EdgeInsets.symmetric(
                                                  horizontal: 5,
                                                ),
                                                shape: RoundedRectangleBorder(
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            10))),
                                            icon: Icon(Icons.edit),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          ),
                        );
                      },
                    ),
                  ),
                );
              } else {
                return Center(
                  child: CircularProgressIndicator(),
                );
              }
            }),
        Align(
          alignment: AlignmentDirectional.bottomCenter,
          child: ElevatedButton(
            onPressed: () {
              Navigator.of(context).pushNamed('/addNewAddress');
            },
            child: Text(
              &quot;Add New Address&quot;,
              style: TextStyle(
                fontSize: 15,
                letterSpacing: 2,
                color: Colors.black,
              ),
            ),
            style: ElevatedButton.styleFrom(
                fixedSize: Size(250, 40),
                primary: Colors.green.shade500,
                padding: EdgeInsets.symmetric(
                  horizontal: 50,
                ),
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10))),
          ),
        ),
      ],
    ),
  );
  }
  }
  </code></pre>
  <p>This is so far I did. Please help me to continue.</p>