美文网首页Flutter
flutter之build(BuildContext conte

flutter之build(BuildContext conte

作者: frankisbaby | 来源:发表于2019-01-23 17:47 被阅读47次

    StatelessWidget是一个抽象类继承自Widget,这个抽象类中定义了build方法:

    Widget build(BuildContext context);

    功能:

    Describes the part of the user interface represented by this widget.

    描述这个widget所代表的用户界面的部分,感觉类似于iOS视图控制器中的viewdidload;

    调用时机:

    The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes).

    framework会调用这个方法:1.当这个widget被插入到给定 BuildContext 的中的时候;2.当widget的依赖改变的时候;

    方式:

    framework会用这个方法返回的widget取代这个widget下边的子树,或者更新已经存在的子树,或者删除子树用新子树填充;这依赖于方法返回的widget是否可以更新已经存在的子树的根,或者是widget调用canUpdate;

    使用条件:

    1.这个widget的区域不能随时间改变;

    2.从context使用 BuildContext.inheritFromWidgetOfExactType获得的任何环境状态。

    相关文章

      网友评论

        本文标题:flutter之build(BuildContext conte

        本文链接:https://www.haomeiwen.com/subject/lpuqdqtx.html