I want to use a DateTime variable in getx and use selectedDate in otherPage as variable in Condition my Controller code :
class HomeController extends GetxController {
RxBool getMyPerm = false.obs;
Rx<DateTime> selectedDate = DateTime.now().obs;
@override
void onInit() {
// TODO: implement onInit
super.onInit();
selectedDate =
DateTime(selectedDate.year, selectedDate.month, selectedDate.day);
}
}
but flutter show me this error : type Rx< DateTime> is not a subtype of type 'DateTime' in type cast
CodePudding user response:
You can't assign a DateTime to an Rx, this is the line that's causing the issue :
selectedDate = DateTime(selectedDate.year, selectedDate.month, selectedDate.day);
in order to assign the value of the RX variable you have to do it through the value property like the following :
selectedDate.value =
DateTime(selectedDate.year, selectedDate.month, selectedDate.day);