這是我的代碼
DateTimeFormField(
decoration: InputDecoration(
hintStyle: const TextStyle(color: Colors.black),
errorStyle: const TextStyle(color: Colors.redAccent),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
hintText: 'MM DD, YYYY',
filled: true,
fillColor: Colors.grey[200],
suffixIcon: const Icon(Icons.event_note),
labelText: 'Select Date',
),
mode: DateTimeFieldPickerMode.date,
autovalidateMode: AutovalidateMode.always,
validator: (e) =>
(e?.day ?? 0) == 1
? 'Please not the first day'
: null,
onDateSelected: (DateTime value) {
// value = populdate;
},
),
我想將選定的日期值放入一個變數中。如何做到這一點,嘗試了很多東西,但沒有得到解決方案。
uj5u.com熱心網友回復:
我認為您已經設定了值,但忘記更新狀態
onDateSelected: (DateTime value) {
// value that you got on every changes happened
populdate= value;
print(populdate); // this should be printed an Instance of DateTime
setState((){}); // update state, and rebuild the UI with latest value
},
uj5u.com熱心網友回復:
試試下面的代碼:
onDateSelected: (DateTime value) {
setState((){
populdate= value;
});},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/523340.html
