如何检查窗口小部件/页面是否被渲染? [英] How to check if a widget/page is rendered?

查看:51
本文介绍了如何检查窗口小部件/页面是否被渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RN中是否有类似componentWillDisapear()的东西?

Is there anything like componentWillDisapear() in RN?

我的问题的详细信息:

我有两个屏幕:主页"和详细信息".我的应用程序使用"firebase_admob"进行广告,而"firebase_admob"(请参见下面的屏幕截图)只能为整个应用程序呈现固定的横幅.因此,当您转到其他屏幕时,您也可以看到它,但是我仅在主屏幕中需要它.这意味着,当用户导航到详细信息"时,我必须将其隐藏.怎么做?

I have two screens: Home and Details. My application uses 'firebase_admob' for adverts and the 'firebase_admob' (see the screenshot below) can render only fixed banner for the whole application. So when you go to other screens you see it too, but I need it only at Home screen. It means, when user navigates to Details I have to hide it. How to do it?

注意:当用户离开主屏幕时,我想呼叫dispose().要渲染横幅,您需要在BannerAd类中调用show(),而当您需要隐藏时,只需调用dispose.

Note: I want to call dispose() when a user leaves the Home screen. To render the banner you need to call show() in BannerAd class and when you need to hide you just call dispose.

推荐答案

下面的代码允许检查用户是否可以看到该页面:

The code bellow allows to check if the page is visible for a user:

import 'package:flutter/material.dart';

class TestWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    print('TestWidget: ${ModalRoute.of(context).isCurrent}');
    return Container();
  }
}

示例允许检查何时更改了路线.但是您无法获得当前页面名称.

And this sample allows to check when a route is changed. But you can't get current page name.

这篇关于如何检查窗口小部件/页面是否被渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆