findLifecycleOwner<LO extends LifecycleOwner> method

LO? findLifecycleOwner<LO extends LifecycleOwner>({
  1. bool test(
    1. LO
    )?,
})

从当前环境中向上寻找特定的 LifecycleOwner

Implementation

LO? findLifecycleOwner<LO extends LifecycleOwner>({bool Function(LO)? test}) {
  Lifecycle? life = toLifecycle();
  if (test == null) {
    while (life != null) {
      if (life.owner is LO) {
        return (life.owner as LO);
      }
      life = life.parent;
    }
    return null;
  }
  while (life != null) {
    if (life.owner is LO && test((life.owner as LO))) {
      return (life.owner as LO);
    }
    life = life.parent;
  }
  return null;
}