如何检查窗口小部件/页面是否被渲染?

编程入门 行业动态 更新时间:2024-10-25 19:30:19
本文介绍了如何检查窗口小部件/页面是否被渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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.

更多推荐

如何检查窗口小部件/页面是否被渲染?

本文发布于:2023-07-20 17:52:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:部件   窗口   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!