rh2o
rh2o

Reputation: 105

How can I handle a list of checkboxes according to a list from FireStore created in flutter?

I have a ListView mapping on documents in the FireStore , i want to check each one separately and uncheck it when press again

can you pleas show me they way according to this code with some notes cause am beginner here

this is my code :

class MyTask extends StatefulWidget {
  @override
  _MyTaskState createState() => _MyTaskState();
}

class _MyTaskState extends State<MyTask> {
 
  @override
  Widget build(BuildContext context) {
  
    return Scaffold(
  
      body: Container(
        child: StreamBuilder(
            stream: FirebaseFirestore.instance
                .collection('users')
                .doc('all')
                .collection(user.uid)
                .snapshots(),
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                return ListView(
                    children: snapshot.data.docs
                        .map<Widget>((DocumentSnapshot document) {
                      return Container(
                        width:200,
                         height:200,
                        child: Column(
                   
                          children: [
                      Text('Title : ${document.data()['title''),
                      
                         
                                Checkbox(
                                    value:,
                                    onChanged: (val) {
                                      

                                    }),
);
}).tolist();

Upvotes: 0

Views: 161

Answers (1)

rh2o
rh2o

Reputation: 105

I added a bool value in the FireStore document and in the code did the following

GestureDetector(
                                  onTap: () {
                                    document.data()['done'] == true
                                        ? AuthServices().unCheckShared(
                                            document.id, _collectionId)
                                        : AuthServices().updateShared(
                                            document.id, _collectionId);
                                  },
                                  child: document.data()['done']
                                      ? Icon(Icons.crop_square, size: 30)
                                      : Icon(Icons.check_box, size: 30),
     
                           ),

Upvotes: 1

Related Questions