updateCPListItem static method

void updateCPListItem(
  1. CPListItem updatedListItem
)

Implementation

static void updateCPListItem(CPListItem updatedListItem) {
  _methodChannel.invokeMethod('updateListItem', <String, dynamic>{
    ...updatedListItem.toJson(),
  }).then((value) {
    if (value) {
      l1:
      for (var h in templateHistory) {
        switch (h) {
          case CPTabBarTemplate _:
            for (var t in h.templates) {
              if (t is CPListTemplate) {
                for (var s in t.sections) {
                  for (var i in s.items) {
                    if (i.uniqueId == updatedListItem.uniqueId) {
                      final tabBar = currentRootTemplate as CPTabBarTemplate;
                      final templateIndex = tabBar.templates.indexOf(t);
                      final listTemplate = tabBar.templates[templateIndex] as CPListTemplate;
                      listTemplate
                          .sections[t.sections.indexOf(s)]
                          .items[s.items.indexOf(i)] = updatedListItem;
                      break l1;
                    }
                  }
                }
              }
            }
            break;
          case CPListTemplate _:
            for (var s in h.sections) {
              for (var i in s.items) {
                if (i.uniqueId == updatedListItem.uniqueId) {
                  (currentRootTemplate as CPListTemplate)
                      .sections[(currentRootTemplate as CPListTemplate)
                          .sections
                          .indexOf(s)]
                      .items[s.items.indexOf(i)] = updatedListItem;
                  break l1;
                }
              }
            }
            break;
          default:
        }
      }
    }
  });
}