颤振类型 'Rx'不是“DateTime”类型的子类型;在类型转换中
我想在 getx 中使用 DateTime 变量 并使用 otherPage 中的 selectedDate 作为 Condition 中的变量 我的控制器代码:
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);
}
}
但是 flutter 显示了这个错误: 类型Rx<日期时间>不是类型转换中“DateTime”类型的子类型
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法将 DateTime 分配给 Rx,这是导致问题的行:
为了分配 RX 变量的值,您必须通过 value 属性来执行此操作,如下所示:
You can't assign a DateTime to an Rx, this is the line that's causing the issue :
in order to assign the value of the RX variable you have to do it through the value property like the following :