0

I am trying to pick a date only. I used flutter_holo_date_picker dependency. When I select date I get time with it. But I only want date not time. How can I remove it?

Here is my code -

import 'package:flutter/material.dart';
import 'package:flutter_holo_date_picker/flutter_holo_date_picker.dart';

class WidgetPage extends StatefulWidget {
  @override
  _WidgetPageState createState() => _WidgetPageState();
}

class _WidgetPageState extends State<WidgetPage> {
  late DateTime _selectedDate;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Center(
          child: Container(
            padding: const EdgeInsets.symmetric(horizontal: 25),
            child: Expanded(
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: DatePickerWidget(
                      looping: false, // default is not looping
                      firstDate: DateTime(1990, 01, 01),
                      lastDate: DateTime(2030, 1, 1),
                      initialDate: DateTime(1991, 10, 12),
                      dateFormat: "dd-MMM-yyyy",
                      locale: DatePicker.localeFromString('en'),
                      onChange: (DateTime newDate, _) =>
                          _selectedDate = newDate,
                      pickerTheme: const DateTimePickerTheme(
                        itemTextStyle:
                            TextStyle(color: Colors.black, fontSize: 19),
                        dividerColor: Colors.blue,
                      ),
                    ),
                  ),
                  Expanded(
                    child: TextButton(
                      onPressed: (){
                        print('current_date: $_selectedDate');
                      },
                      child: const Text('submit'),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Output - 1

Expected output will be -

current_date: 2022-1-1

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
M.Jehan
  • 1
  • 2
  • 2

1 Answers1

0

DatePickerWidget's onChange method provide DateTime. You can format this date with DateFormat from intl package.

final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String output = formatter.format(_selectedDate);

I will encourage you to check this answer.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56