Is there a way to add a checkbox dynamically

Description

Is there a way to add a checked box dynamically

What MCU/Processor/Board and compiler are you using?

ESP32 S3

What LVGL version are you using?

v8.3.4

What do you want to achieve?

Created the Initial List of Checkboxes

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
void init_todoList(lv_obj_t* scr,lv_obj_t* list,lv_style_t* list_style){
    lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
    lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER);

    list = lv_obj_create(lv_scr_act());
    lv_obj_set_size(list, 240, 240);
    lv_obj_center(list);
    lv_obj_set_flex_flow(list, LV_FLEX_FLOW_COLUMN);
    lv_obj_add_event_cb(list, scroll_event_cb, LV_EVENT_SCROLL, NULL);
    lv_obj_set_style_radius(list, LV_RADIUS_CIRCLE, 0);
    lv_obj_set_style_clip_corner(list, true, 0);
    lv_obj_set_scroll_dir(list, LV_DIR_VER);
    lv_obj_set_scroll_snap_y(list, LV_SCROLL_SNAP_CENTER);
    lv_obj_set_scrollbar_mode(list, LV_SCROLLBAR_MODE_OFF);

    uint32_t i;
    for(i = 0; i < 5; i++) {
        todoList_check_boxes = lv_checkbox_create(list);
        lv_checkbox_set_text(todoList_check_boxes, "Apple");
        // lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
    }

    lv_obj_t * btn = lv_btn_create(list);
    lv_obj_set_width(btn, lv_pct(200));
    lv_obj_add_event_cb(btn, add_button_pressed, LV_EVENT_CLICKED, NULL);

    lv_obj_t * label = lv_label_create(btn);
    lv_label_set_text_fmt(label,"Add Event");

    /*Update the buttons position manually for first*/
    lv_event_send(list, LV_EVENT_SCROLL, NULL);

    /*Be sure the fist button is in the middle*/
    lv_obj_scroll_to_view(lv_obj_get_child(list, 0), LV_ANIM_OFF);
}

void add_button_pressed(lv_event_t * e){
    if(lv_event_get_code(e) == LV_EVENT_CLICKED){
        todoList_check_boxes = lv_checkbox_create(todoList);
        lv_checkbox_set_text(todoList_check_boxes, "Banana");
    }
}

Just trying to figure how to add a new checked box to a initial list of checkboxes, wanted to do a basic to-do list but this does not add a new checkbox to the list. I tried looking through the documentation but I did not find a way (sorry if its something very trivial!). Thanks!

Yes if your todoList is global .

Thanks for the reply. I was able to do that by creating a static pointer to the checkbox list and then updating it accordingly to the events.