flutter 如果有界面数据销毁不了,那就再dispose的时候把界面隐藏了,当没来过

如果有界面数据销毁不了,那就再dispose的时候把界面隐藏了,当没来过
特别像这种,多个地方用一个对象,可能这个对象销毁不了,所以就在该对象销毁的时候,设置是否可以显示的状态,让整个画面都隐藏掉(用offstage),下次再调用这个对象时就不会有影响了

CoverScreen? _coverScreen;

Future<bool> showGiftPlay(
    {
    
    required BuildContext context,
    required gift.GiftBean giftBean,
    PlayState? playState,
    int? type}) {
    
    
  print(
      'AnimationStatus initState====== 类型${
    
    type}');

  if (_coverScreen?.isShow ?? false) {
    
    
    if (giftBean.id == Global.showGiftBean?.id) {
    
    
      print(
          'AnimationStatus initState======传进来的礼物ID${
    
    giftBean.id}  当前礼物ID${
    
    Global.showGiftBean?.id}');
      return Future.value(true);
    }
  }
  print('AnimationStatus initState======不是当前礼物ID,加入队列');
  _coverScreen = CoverScreen(
      child: SvgaDialog(
    giftBean: giftBean,
    playState: playState,
  ));
  Global.showGiftBean = giftBean;

  _coverScreen?.show();
  return Future.value(_coverScreen?.isShow);
}

hidden() {
    
    
  if (_coverScreen != null) {
    
    
    _coverScreen?.hidden();
  }
}

onDispose() {
    
    
  if (_coverScreen != null) {
    
    
    _coverScreen?.ondispose();
  }
}

猜你喜欢

转载自blog.csdn.net/weixin_44911775/article/details/131942370
今日推荐