hARASİVa
hARASİVa

Reputation: 25

How to use Getx state management without using Getview?

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

Upvotes: 1

Views: 2229

Answers (2)

Lab
Lab

Reputation: 1387

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(),
    );
  }
}

Upvotes: 2

Arbiter Chil
Arbiter Chil

Reputation: 1255

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

Upvotes: 1

Related Questions