以下のコードは正常に機能しています。しかし、デフォルトの日付値を設定する方法がわかりません!
final dateFormat = DateFormat("dd-M-yyyy");
DateTimePickerFormField(
dateOnly: true,
format: dateFormat,
decoration: InputDecoration(labelText: 'Select Date'),
initialDate: DateTime.now(),
onSaved: (value){
_date = value;
},
),
datetime_picker_formfield:
フラッターライブラリを使用しています。
initialDate: DateTime.now()
初期日付プロパティを使用してこれを実行しようとしていますが、初期値として何も表示されませんでした。
前もって感謝します!
使用する必要のある最初の日付値を表示するには- initialValue:
initialDate:
データピッカーが言及された日付を表示するためのものです。
DateTimePickerFormField(
dateOnly: true,
format: dateFormat,
decoration: InputDecoration(labelText: 'Select Date'),
initialValue: DateTime.now(), //Add this in your Code.
// initialDate: DateTime(2017),
onSaved: (value) {
debugPrint(value.toString());
},
),
バリデーターで更新されたコード:
var _myKey = GlobalKey<FormState>();
final dateFormat = DateFormat("dd-M-yyyy");
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Form(
key: _myKey,
child: Center(
child: DateTimePickerFormField(
dateOnly: true,
format: dateFormat,
validator: (val) {
if (val != null) {
return null;
} else {
return 'Date Field is Empty';
}
},
decoration: InputDecoration(labelText: 'Select Date'),
initialValue: DateTime.now(), //Add this in your Code.
// initialDate: DateTime(2017),
onSaved: (value) {
debugPrint(value.toString());
},
),
),
),
RaisedButton(
onPressed: () {
if (_myKey.currentState.validate()) {
_myKey.currentState.save();
} else {
}
},
child: Text('Submit'),
)
],
);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加