如何解决flutter中的showDatePicker区域(方法'formatFullDate'在null上调用。)

时间:2020-02-07 08:52:51

标签: flutter dart

在构建Directionality(textDirection:ltr)时引发了以下NoSuchMethodError:在null上调用了'formatFullDate'方法。

RaisedButton.icon(
  icon: Icon(Icons.date_range),
  label: Text('Start'),
  onPressed: () async {
    var date = await showDatePicker(
      context: context,
      initialDate: DateTime.now(),
      locale: Locale.fromSubtags(
        countryCode: 'KE',
        languageCode: 'EN',
      ),
      firstDate: DateTime(2008),
      useRootNavigator: true,
      lastDate: DateTime.now(),
      builder: (context, widget) => widget,
    );
    print(date);
  },
),

2 个答案:

答案 0 :(得分:0)

我意识到本地化是错误的。通过

对其进行了修复
locale: Locale.fromSubtags(
          countryCode: 'en',
          languageCode: 'US',
      ),

答案 1 :(得分:0)

怎么样?

locale: Locale.fromSubtags(
  countryCode: 'KE',
  languageCode: 'en',
),