0

I am using getx get: ^4.3.8 as the state management component in flutter, when I using this code to update the controller value:

var expand = controller.newTaskExpanded.value;
controller.newTaskExpanded(!expand);

I found the component did not refresh, then I have to invoke the getx refresh function like this:

controller.refresh();

this is the controller properties define:

class HomeController extends GetxController {
  List<Widget> widgetsList = List.empty(growable: true);
  List<Todo> tasks = List.empty(growable: true);
  var newTaskExpanded = true.obs;
  var completedTaskExpanded = false.obs;
}

is is possible to auto refresh the flutter component when controller properties value changed? should I invoke the refresh function every time change the value of getx controller?

1
  • 1
    have you tried adding Obx on the widget or getbuilder then using update(). ? Commented Jul 9, 2022 at 5:20

3 Answers 3

3

Reactive programming with Get is as easy as using setState.

Let's imagine that you have a name variable and want that every time you change it, all widgets that use it are automatically changed.

This is your count variable:

var name = 'Jonatas Borges';

To make it observable, you just need to add ".obs" to the end of it:

var name = 'Jonatas Borges'.obs;

And in the UI, when you want to show that value and update the screen whenever the values changes, simply do this:

Obx(() => Text("${controller.name}"));

For more , refer: https://pub.dev/packages/get/example

Sign up to request clarification or add additional context in comments.

Comments

2

wrap you UI with Obx builder like

appBar: AppBar(title: Obx(() => Text("Clicks: ${c.count}"))),

it will auto refresh the UI on value change if you want to refresh the UI manually then use GetBuilder and when you need to update the UI just call controller.update();

Comments

2

As @Muhammad Sherad explained, your widget code should be wrapped with Obx() so that you widget can look for variable change and re-render the widget.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.