addNewCard method

Future addNewCard({
  1. required String position,
  2. required int listIndex,
})

Implementation

Future addNewCard({required String position, required int listIndex}) async {
  var prov = ref.read(ProviderList.boardProvider);
  if (prov.board.newCardFocused == true) {
    ref.read(ProviderList.cardProvider).saveNewCard();
  }

  var scroll = prov.board.lists[listIndex].scrollController;

  // log("MAX EXTENT =${scroll.position.maxScrollExtent}");

  prov.board.lists[listIndex].items.insert(
      position == "TOP" ? 0 : prov.board.lists[listIndex].items.length,
      ListItem(
        child: Container(
            width: prov.board.lists[listIndex].width,
            color: Colors.white,
            margin: const EdgeInsets.only(bottom: 10),
            child: const TField()),
        listIndex: listIndex,
        isNew: true,
        index: prov.board.lists[listIndex].items.length,
        prevChild: Container(
            width: prov.board.lists[listIndex].width,
            color: Colors.white,
            margin: const EdgeInsets.only(bottom: 10),
            padding: const EdgeInsets.all(10),
            child: const TField()),
      ));
  position == "TOP" ? await scrollToMin(scroll) : scrollToMax(scroll);
  prov.board.newCardListIndex = listIndex;
  prov.board.newCardFocused = true;
  prov.board.newCardIndex =
      position == "TOP" ? 0 : prov.board.lists[listIndex].items.length - 1;
  prov.board.lists[listIndex].setState!();
}