If flutter has interface data that cannot be destroyed, then hide the interface when disposing, as if it has never been there

If there is interface data that cannot be destroyed, then hide the interface when disposing. If you have never been here, it is
especially like this. If you use an object in multiple places, the object may not be destroyed, so when the object is destroyed, set Whether the state can be displayed, so that the entire screen is hidden (using offstage), and it will not be affected when the object is called next time

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();
  }
}

Guess you like

Origin blog.csdn.net/weixin_44911775/article/details/131942370