I am trying to pull the variable named _pageIndex
from a file called GetX welcomeMain.dart
and change its value
.
welcomeMain.dart
:
class getPageIndex extends GetxController {
int _pageIndex = 0;
increment() => _pageIndex;
}
And I also try to call _pageIndex
and change its value like this:
onPressed: () {
final getPageIndex _getPageIndex = Get.put(getPageIndex());
_getPageIndex._pageIndex = 2;
},
But I am getting error:
The setter '_pageIndex' isn't defined for the type 'getPageIndex'.
Try importing the library that defines '_pageIndex', correcting the name to the name of an existing setter, or defining a setter or field named '_pageIndex'.
What is the problem? How can I solve it?
CodePudding user response:
The problem is underscoring, which makes your variable private. Just remove it.
int pageIndex = 0;