onItemClick method

  1. @override
void onItemClick(
  1. int tabIndex,
  2. String name,
  3. String code
)
override

点击事件 tabIndex:当前 tab 索引 name:城市名称 code:城市代码

Implementation

@override
void onItemClick(int tabIndex, String name, String code) {
  if (_isClick) {
    return;
  }
  _isClick = true;

  // 点击永远是移动到下一个 tab
  _currentIndex++;
  // 先把后面的全部删除
  if (_selectData.length >= _currentIndex) {
    _selectData.removeRange(_currentIndex - 1, _selectData.length);
    _myTabs.removeRange(_currentIndex, _myTabs.length);
    _tabController = TabController(
        vsync: this, length: _myTabs.length, initialIndex: _currentIndex - 1);
    if (mounted) {
      setState(() {});
    }
  }

  _selectData.insert(_currentIndex - 1, AddressNode(code: code, name: name));
  _myTabs.elementAt(_currentIndex - 1).title =
      _selectData[_currentIndex - 1].name;

  widget.cityPickerListener!
      .onDataLoad(_currentIndex, code, name)
      .then((value) {
    List<SectionCity> list = sortCity(value);
    if (list.isEmpty) {
      _isClick = false;
      if (mounted) {
        setState(() {});
      }
      widget.cityPickerListener!.onFinish(_selectData);
      Navigator.pop(context);
    } else {
      _mData[_currentIndex] = list;
      _myTabs.add(
          TabTitle(index: _currentIndex, title: widget.selectText ?? "请选择"));
      _tabController = TabController(
          vsync: this, length: _myTabs.length, initialIndex: _currentIndex);
      _pageController!.animateToPage(_currentIndex,
          duration: const Duration(milliseconds: 10), curve: Curves.linear);
      _isClick = false;
      if (mounted) {
        setState(() {});
      }
    }
  });
}