Home > Software engineering >  Flutter : (GetX) RxInt
Flutter : (GetX) RxInt

Time:03-04

I made a program that changes the shape when the button is pressed I used (IndexedStack) Each time the button is pressed, a different shape appears But I get a lot of problems that I can't solve

IndexedStack(
index: controller.IndexedStackSelected.value,
children: [
Container(),
Container(),
]
),

The button

controller.buttontwo();
controller.buttonone();

type 'int' is not a subtype of type 'RxInt' of 'function result'

Controller

import 'package:flutter/material.dart';
import 'package:get/get.dart';

class HomeController extends GetxController {

  late int minutsave ;
  RxInt IndexedStackSelected = 0.obs;

  void buttonone() {
    IndexedStackSelected = 0 as RxInt;
  }

  void buttontwo() {
    IndexedStackSelected = 1 as RxInt;
  }

When I use (Obx) in the code it tells me :

[Get] the improper use of a GetX has been detected. You should only use GetX or Obx for the specific widget that will be updated. If you are seeing this error, you probably did not insert any observable variables into GetX/Obx

CodePudding user response:

Try with this. And refer this code for GetX. getx_controller_example

IndexedStack(
index: controller.IndexedStackSelected,
children: [
Container(),
Container(),
]
),

//

class HomeController extends GetxController {

var _indexedStackSelected = 0.obs;

int get IndexedStackSelected => _indexedStackSelected.value;

void buttonone() {
    _indexedStackSelected.value = 0;
  }

  void buttontwo() {
    _indexedStackSelected.value = 1;
  }
  • Related