How to get Flutter FormBuilderDateTimePicker to show only the date picker
Asked Answered
I

2

7

How can I get the Flutter FormBuilderDateTimePicker to only show the date? The code below produces a time picker after the date picker closes and the output is:

flutter: 2022-04-02 00:00:00.000

I could strip the time using DateTime.timeonly() but that doesn't solve the problem. This should be a date only field.

FormBuilderDateTimePicker(
    name: 'date_established',
    format: DateFormat('dd/MM/yyyy'),
    enabled: true,
    decoration: InputDecoration(
        labelText: 'Date Established',
        labelStyle: TextStyle(
            color: Colors.white,
            fontSize: 16.0,
            fontWeight: FontWeight.normal)),
        style: TextStyle(
            color: Colors.white,
            fontSize: 16.0,
            fontWeight: FontWeight.normal),
),
Indispose answered 3/4, 2022 at 2:28 Comment(0)
P
5
var _selectedDate;
DateTime? datePicked;

    Future<void> _showDObPicker() async {
        datePicked = await showDatePicker(
            context: context,
            initialDate: DateTime.now(),
            firstDate: DateTime(1900,1,1),
            lastDate: DateTime.now(),
            builder: (BuildContext context, Widget? child) {
              return Theme(
                data: ThemeData.light().copyWith(
                  colorScheme: ColorScheme.light(primary: kPrimaryColor),
                  buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary),
                ),
                child: child!,
              );
            });
    
        setState(() {
    
          _selectedDate = DateFormat("dd/MM/yyyy").format(datePicked!);
    
        });
      }

Declare a method like this & use it like below

hint: _selectedDate
Passable answered 3/4, 2022 at 5:2 Comment(0)
I
13

The solution was to add

inputType: InputType.date,
Indispose answered 3/4, 2022 at 4:16 Comment(0)
P
5
var _selectedDate;
DateTime? datePicked;

    Future<void> _showDObPicker() async {
        datePicked = await showDatePicker(
            context: context,
            initialDate: DateTime.now(),
            firstDate: DateTime(1900,1,1),
            lastDate: DateTime.now(),
            builder: (BuildContext context, Widget? child) {
              return Theme(
                data: ThemeData.light().copyWith(
                  colorScheme: ColorScheme.light(primary: kPrimaryColor),
                  buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary),
                ),
                child: child!,
              );
            });
    
        setState(() {
    
          _selectedDate = DateFormat("dd/MM/yyyy").format(datePicked!);
    
        });
      }

Declare a method like this & use it like below

hint: _selectedDate
Passable answered 3/4, 2022 at 5:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.