Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to assign the value of selected date to a variable

This is my code

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;
  },
),

I want to put the selected date value into a variable. How to do that, tried many things but didn’t get a solution.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

i think you already set the value, but forget to update the state

  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
  },
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading