对flutter生命周期不了解,遇到的问题:

@override
  void didChangeDependencies() {
    // 放在didChangeDependencies里push下页pop上页会执行两次,tabbar是正常的
    //放在deactivate里,其他tabbar的isCurrent也是true会执行load
    print('执行didChangeDependencies');
    if (ModalRoute.of(context).isCurrent) {
      load();
    }
  }
void load () {
    HospitalApi.hasJoin().then((res) {
      _showCreate();
      if (res == null) {
        _showCreate();
      } else {
        setState(() {
          _hospitalInfo = res;
        });
      }
    });
  }
Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐