showTab method

void showTab(
  1. String? url, {
  2. bool refresh = false,
  3. String? dependency,
  4. String? title,
  5. bool? closeable,
  6. String? icon,
})

Implementation

void showTab(String? url, {bool refresh = false, String? dependency, String? title, bool? closeable, String? icon}) {

  // String template = uri.host;
  var uri = URI.parse(url);
  if (uri == null) return;

  var id = uri.url.toLowerCase();
  if (id == 'previous') return showPreviousTab();
  if (id == 'next') return showNextTab();
  if (id == 'first') return showFirstTab();
  if (id == 'last') return showLastTab();

  // get tab by matching id
  var tab = tabs.firstWhereOrNull((tab) => tab.url == uri.url);

  // New Tab
  if (tab == null || refresh) {

    // title
    title = title ?? uri.queryParameters['title'] ?? uri.page.toString();

    // icon
    icon = icon ?? uri.queryParameters['icon'];

    // closeable
    closeable = closeable ?? toBool(uri.queryParameters['closeable']) ?? true;

    // build tab
    tab = TabModel(this, id, url: uri.url, title: title, closeable: closeable, icon: icon, dependency: dependency);
    tabs.add(tab);

    // add framework child
    tab.children ??= [];
    tab.children!.add(FrameworkModel.fromUrl(tab, uri.url, dependency: dependency));
  }

  // set the current index
  index = tabs.indexOf(tab);
}