Skip to content

add parameter on DatePickerThemeData to customize the text style of the toggle mode button #163866

@MaironLucas

Description

@MaironLucas

Use case

It is not possible to customize the text style of the toggle mode button of the DatePickerDialog using the DatePickerTheme.

To be able to achieve this customization, it's necessary to wrap the dialog with a Theme and change the textTheme, as in the example below:

class DatePickerExample extends StatelessWidget {
  const DatePickerExample({super.key});

  @override
  Widget build(BuildContext context) => Scaffold(
        body: Center(
          child: ElevatedButton(
            onPressed: () => showDatePicker(
              context: context,
              firstDate: DateTime(2025),
              lastDate: DateTime(2026),
              builder: (context, child) => Theme(
                data: ThemeData.light().copyWith(
                  textTheme: TextTheme(
                      titleSmall: TextStyle(
                      fontSize: 16,
                    ),
                  ),
                  datePickerTheme: DatePickerThemeData(
                      dayStyle: TextStyle(
                    fontSize: 12,
                  )),
                ),
                child: child!,
              ),
            ),
            child: Text('Show Date Picker'),
          ),
        ),
      );
}

Proposal

It would be better if DatePickerThemeData had a parameter to explicitly set the style for the toggle button, so just a wrap with a DatePickerTheme would be enough to customize the dialog widget. Something like:

class DatePickerExample extends StatelessWidget {
  const DatePickerExample({super.key});

  @override
  Widget build(BuildContext context) => Scaffold(
        body: Center(
          child: ElevatedButton(
            onPressed: () => showDatePicker(
              context: context,
              firstDate: DateTime(2025),
              lastDate: DateTime(2026),
              builder: (context, child) => DatePickerTheme(
                data: DatePickerThemeData(
                  toggleModeStyle: TextStyle(
                      fontSize: 16,
                    ),
                  dayStyle: TextStyle(
                    fontSize: 12,
                  ),
                ),
                child: child!,
              ),
            ),
            child: Text('Show Date Picker'),
          ),
        ),
      );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: date/time pickerDate or time picker widgetsf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions