Flutter-showDatePicker将一周的第一天设置为星期一

时间:2019-09-17 13:28:10

标签: flutter

我正在使用抖动showDatePicker小部件https://api.flutter.dev/flutter/material/showDatePicker.html

默认情况下,当日期选择器弹出窗口加载时,星期的开始是星期日,我想将其更改为星期一。

关于如何实现此目标的任何建议?

Future<void> _selectDate(BuildContext context) async {
    final DateTime picked = await showDatePicker(
      context: context,
      initialDate: _selectedDate,
      firstDate: firstDate,
      lastDate: lastDate,
      locale: const Locale('en', 'GB'),
    );
    if (picked != null && picked != _selectedDate) {
      // update the calendar slider with new date
      setState(() {
        _selectedDate = picked.add(Duration(hours: 1));
      });
    }

enter image description here

1 个答案:

答案 0 :(得分:1)

添加一个将星期一作为一周的第一天的locale,例如:

  Future<DateTime> selectedDate = showDatePicker(
    context: context,
    locale: const Locale('en', 'GB'),
    // etc

您还必须按照here的说明添加本地化库,并将其添加到MaterialApp

  localizationsDelegates: GlobalMaterialLocalizations.delegates,
  supportedLocales: [
    const Locale('en', 'US'),
    const Locale('en', 'GB'),
  ],