Flutter:Widget构建上的Run方法已完成 [英] Flutter: Run method on Widget build complete

查看:75
本文介绍了Flutter:Widget构建上的Run方法已完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小部件完成构建/加载后,我希望能够运行功能,但是我不确定如何运行。
我当前的用例是检查用户是否已通过身份验证,如果未通过身份验证,则重定向到登录视图。我不想先检查并推送登录视图或主视图,它需要在主视图加载后进行。
有什么我可以用来做的吗?

I would like to be able to run functions once a Widget has finished building/loading but I am unsure how. My current use case is to check if a user is authenticated and if not, redirect to a login view. I do not want to check before and push either the login view or the main view, it needs to happen after the main view has loaded. Is there anything I can use to do this?

推荐答案

您可以使用

https://github.com/slightfoot/flutter_after_layout

仅在布局完成后执行一次功能。
或仅查看其实现并将其添加到您的代码中:-)

which executes a function only one time after the layout is completed. Or just look at its implementation and add it to your code :-)

基本上是哪个

  void initState() {
    super.initState();
    WidgetsBinding.instance
        .addPostFrameCallback((_) => yourFunction(context));
  }

这篇关于Flutter:Widget构建上的Run方法已完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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