Life cycle in flutter

前端 未结 8 824
予麋鹿
予麋鹿 2020-12-07 10:48

Does flutter have a method like Activity.resume() which can tell developer the user has gone back to the activity.

When I pick the data from internet in

8条回答
  •  离开以前
    2020-12-07 11:31

    1. createState(): When we create a stateful widget, the Flutter framework instruct to createState() method.

      @override _DeveloperLibsWidgetState createState() => _DeveloperLibsWidgetState();

    2.mounted(true/false): Once we create a State object, the framework mounted the State object by associating it with a BuildContext before calling initState() method. All widgets have a bool mounted property. It is turned true when the buildContext is assigned.

    bool get mounted => _element != null;
    
    1. initState(): This is the first method called when a stateful widget is created after the class constructor. The initState() is called only once. It must called super.initState().

      @override initState() { super.initState(); // TO DO }

    2. didChangeDependencies(): This method is called immediately after initState() method on the first time the widget is built.

      @protected @mustCallSuper void didChangeDependencies() {

      }

    3. build(): it shows the part of the user interface represented by the widget. The framework calls this method in several different situations: After calling initState() method. The framework always calls build() method after calling didUpdateWidget After receiving a call for setState to update the screen.

      @override Widget build(BuildContext context, MyButtonState state) { return Container(color: const Color(0xFF2DBD3A));
      }

    4. didUpdateWidget(Widget oldWidget): If the parent widget change configuration and has to rebuild this widget. But it's being rebuilt with the same runtimeType, then didUpdateWidget() method is called.

      @mustCallSuper @protected void didUpdateWidget(covariant T oldWidget) {

      }

    5. setState(): This method is called from the framework and the developer. We can change the internal state of a State object and make the change in a function that you pass to setState().

      @override _DeveloperLibsWidgetState createState() => _DeveloperLibsWidgetState();

    6. deactivate(): This is called when State is removed from the widgets tree, but it might be reinserted before the current frame change is finished.

      @protected @mustCallSuper void deactivate() { }

    7. dispose(): This is called when the State object is removed permanently. Here you can unsubscribe and cancel all animations, streams, etc.

      @protected @mustCallSuper void dispose() { assert(_debugLifecycleState == _StateLifecycle.ready); assert(() { _debugLifecycleState = _StateLifecycle.defunct; return true; }()); }

提交回复
热议问题