replaceTab static method

void replaceTab(
  1. String title,
  2. Widget page
)

Implementation

static void replaceTab(String title, Widget page) {
  final int existingIndex = tabs.indexWhere((TabData tab) => tab.title == title);

  if (existingIndex != -1) {
    tabs.value = <TabData>[...tabs]..removeAt(existingIndex);

    tabs.value = <TabData>[
      ...tabs.sublist(0, existingIndex),
      TabData(title: title, page: page),
      ...tabs.sublist(existingIndex),
    ];

    if (tabController != null) {
      delay(100, () => tabController!.animateTo(existingIndex));
    }
  } else {
    addTab(title, page);
    if (tabController != null) {
      delay(100, () => tabController!.animateTo(tabs.length - 1));
    }
  }
}