mardi 1 février 2022

Checkboxes are not working properly with matching list of data

I used predefined data for a ui but it is not working. Here is my attempt:

List? authId=[1,3];
  List<CheckBoxModel> checkBoxListTileModel =
  CheckBoxModel.getUsersAuthorization1();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      
      body: ListView.builder(
          itemCount: checkBoxListTileModel.length,
          itemBuilder: (BuildContext context, int index) {
            return Card(
              child: Container(
                padding: EdgeInsets.all(10.0),
                child: Column(
                  children: <Widget>[
                    CheckboxListTile(
dense: true,
title: Text('${checkBoxListTileModel[index].name}',),
                        value: authId==checkBoxListTileModel[index].id ? true : false,
                        onChanged: (bool? val) {
                          checkBoxListTileModel[index].isCheck = val;
                        })
                  ],
                ),
              ),
            );
          }),
    );
  }
}

I can handle in reading the data. I can get them but when i try to change them or used list problem happens. It does not work. When i took authId as an int it works but still not work properly, i cannot change its value.

Here is my list implementation.

class CheckBoxModel {
  int? id;
  String? name;
  bool? isCheck;

  CheckBoxModel({this.id, this.name, this.isCheck});

  static List<CheckBoxModel> getUsersAuthorization1() {
    return <CheckBoxModel> [
          CheckBoxModel(
            id: 1,
            name: 'Get',
            isCheck: false,
          ),
          CheckBoxModel(
            id: 2,
            name: 'Insert',
            isCheck: false,
          ),
          CheckBoxModel(
            id: 3,
            name: 'Update',
            isCheck: false,
          ),
      ];
  }
}



Aucun commentaire:

Enregistrer un commentaire