Home > Blockchain >  How to access View Lifecycle when extending GetView<T>
How to access View Lifecycle when extending GetView<T>

Time:05-11

When a view is inheriting GetView , it's basically a StatelessWidget with additional variable named "controller" which is our entrypoint to access anything inside the GetXController. The problem is, I do not have any control over the view lifecycle like I do in Kotlin android Such as onCreate, onStart, onResume,onPause, onDestroy,etc. when inheriting the GetView which is a StatelessWidget, Can I use a stateful widget together with GetXController?, Will that be a time bom in my application that one day it will cause a problem or performance issue?

CodePudding user response:

GetxController have all lifecycle function you want, just create one and put it in. Cause getx split your view and logic code, all lifecycle function will put in controller.

As you can see GetxController was have GetLifeCycleMixin in there code.

CodePudding user response:

Try using this also you dont need statefull for the lifecycle on that stateless is enough with getview

so try call SuperController or FullLifeCycleController

import 'package:get/get.dart';

class ControllerLifeCycle1 extends SuperController{
  @override
  void onDetached() {
    // TODO: implement onDetached
  }
  @override
  void onInactive() {
    // TODO: implement onInactive
  }
  @override
  void onPaused() {
    // TODO: implement onPaused
  }

  @override
  void onResumed() {
    // TODO: implement onResumed
  }
}

class ControllerLifeCycle2 extends FullLifeCycleController  with FullLifeCycleMixin{
  @override
  void onDetached() {
    // TODO: implement onDetached
  }

  @override
  void onInactive() {
    // TODO: implement onInactive
  }
  @override
  void onPaused() {
    // TODO: implement onPaused
  }
  @override
  void onResumed() {
    // TODO: implement onResumed
  }

}

Just try this both on which one would work for you also they do have onDelete onClose onReady

as for example although it might outdated but just try to make reference above i put.

// I Also looking for lifecycle and stumble this one as per example e.g. gist.github.com/eduardoflorence/d918d05ad71175b52c2aca95588c305d

  • Related