Home > Software design >  How to get Flutter FormBuilderDateTimePicker to show only the date picker
How to get Flutter FormBuilderDateTimePicker to show only the date picker

Time:04-03

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

CodePudding user response:

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

CodePudding user response:

The solution was to add

inputType: InputType.date,
  • Related