hive icon indicating copy to clipboard operation
hive copied to clipboard

Saving checkbox value from pre made list to hive

Open Redmistt opened this issue 3 years ago • 0 comments

Question Hi, i'm trying to make a screen with two listviews, one pre made and one where you add tasks yourself, the pre made list is written in json(doesn't have to be) which works fine but my problem is saving the checkbox state to hive, is there a better way to do this? Let me know if I you need anything else

Code sample

          Visibility(
              visible: categorySelector,
              replacement: ListView.builder(
                  shrinkWrap: true,
                  itemCount: _nbtemplate.length,
                  itemBuilder: (context, index) {
                    return Container(
                      margin: const EdgeInsets.all(4),
                      decoration: BoxDecoration(
                        border: Border.all(
                          width: 2,
                          color: widget.project.isCompleted //||
                              //widget.template.isCompleted
                              ? Colors.green
                              : Colors.grey,
                        ),
                      ),
                      child: ListTile(
                        leading: Checkbox(
                          value: widget.project.isCompleted, //||
                          //widget.template.isCompleted,
                          onChanged: (value) {
                            setState(() {
                              //widget.template.isCompleted = value!;
                            });
                            if (widget.project.isCompleted) {
                              widget.project.isCompleted = false;
                              updateProject(widget.project);
                            }
                            //updateTmpl(widget.project, widget.template, value!);
                          },
                        ),
                        title: Text(
                          _nbtemplate[index]["name"],
                          style: TextStyle(
                            fontSize: 16,
                            fontWeight: FontWeight.w500,
                            decoration: widget.project.isCompleted //||
                                //widget.template.isCompleted
                                ? TextDecoration.lineThrough
                                : null,
                            decorationColor: Colors.green,
                            decorationThickness: 2,
                          ),
                        ),
                        subtitle: Text(
                          _nbtemplate[index]["el"],
                          style: TextStyle(
                            fontSize: 12,
                            decoration: widget.project.isCompleted //||
                                //widget.template.isCompleted
                                ? TextDecoration.lineThrough
                                : null,
                            decorationColor: Colors.green,
                            decorationThickness: 2,
                          ),
                        ),
                      ),
                    );
                  }),
              child: ListView.builder(
                  shrinkWrap: true,
                  itemCount: _shtemplate.length,
                  itemBuilder: (context, index) {
                    return Container(
                      margin: const EdgeInsets.all(4),
                      decoration: BoxDecoration(
                        border: Border.all(
                          width: 2,
                          color: widget.project.isCompleted //||
                              //widget.template.isCompleted
                              ? Colors.green
                              : Colors.grey,
                        ),
                      ),
                      child: ListTile(
                        leading: Checkbox(
                          value: widget.project.isCompleted, //||
                          //widget.template.isCompleted,
                          onChanged: (value) {
                            setState(() {
                              //widget.template.isCompleted = value!;
                            });
                            if (widget.project.isCompleted) {
                              widget.project.isCompleted = false;
                              updateProject(widget.project);
                            }
                            //updateTmpl(widget.project, widget.template, value!);
                          },
                        ),
                        title: Text(
                          _shtemplate[index]["name"],
                          style: TextStyle(
                            fontSize: 16,
                            fontWeight: FontWeight.w500,
                            decoration: widget.project.isCompleted //||
                                //widget.template.isCompleted
                                ? TextDecoration.lineThrough
                                : null,
                            decorationColor: Colors.green,
                            decorationThickness: 2,
                          ),
                        ),
                        subtitle: Text(
                          _shtemplate[index]["el"],
                          style: TextStyle(
                            fontSize: 12,
                            decoration: widget.project.isCompleted //||
                                //widget.template.isCompleted
                                ? TextDecoration.lineThrough
                                : null,
                            decorationColor: Colors.green,
                            decorationThickness: 2,
                          ),
                        ),
                      ),
                    );
                  })),

Version

  • Platform: iOS, Android, Mac, Windows, Linux, Web
  • Flutter version: [3.0.5]
  • Hive version: [1.1.0]

Redmistt avatar Aug 10 '22 21:08 Redmistt