Home > OS >  How to use Getx state management without using Getview?
How to use Getx state management without using Getview?

Time:06-01

My friends and I are doing a project with Flutter.He doens't use any state management method and I want to use Getx.So how can i use Getx without using Getview class so that our both codes work in a harmony?enter image description here

CodePudding user response:

try this...

class MyView extends StatelessWidget {
  // you can also put it here
  final controller = Get.put(MyController());
  @override
  Widget build(BuildContext context) {
   // you can put it here
   final controller = Get.put(MyController());
    return Text(
      controller.myText.value,
      style: Theme.of(context).textTheme.headline4,
    );
  }
}

either ways try to play with it

CodePudding user response:

If you want to use Getx controllers by keeping StatelessWidget or StatefulWidget, just initialize your controller with GetBuilder

class TestView extends StatelessWidget {
  const TestView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<TestController>(
      init: TestController(),
      builder: (controller) => Scaffold(),
    );
  }
}
  • Related