我想在 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);
}
}
但顫振告訴我這個錯誤:型別 Rx<DateTime> 不是型別轉換中型別“日期時間”的子型別
uj5u.com熱心網友回復:
您不能將 DateTime 分配給 Rx,這是導致問題的行:
selectedDate = DateTime(selectedDate.year, selectedDate.month, selectedDate.day);
為了分配 RX 變數的值,您必須通過 value 屬性來完成,如下所示:
selectedDate.value =
DateTime(selectedDate.year, selectedDate.month, selectedDate.day);
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/439080.html
