我尝试将日历语言从英语更改为韩语。但是上面显示了一些错误。
错误:
没有找到materiallocalization。DatePickerDialog小部件需要由本地化小部件祖先提供的MaterialLocalizations。素材库使用本地化来生成消息、标签和缩写。
这是我的代码。我已经改变了pubspec.yaml
import 'package:flutter_localizations/flutter_localizations.dart'; // library
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
home: buildHomePage(),
);
Future<void> _selectrequestDate(BuildContext context) async {
final DateTime? pickedDate = await showDatePicker(
context: context,
locale : Locale('kr',''),
initialDate: requestDate,
firstDate: DateTime(2015),
lastDate: DateTime(2050));
if (pickedDate != null && pickedDate != requestDate)
setState(() {
requestDate = pickedDate;
});
如何解决这个问题?
根据国际化Flutter应用程序,您还需要在MaterialApp
中添加supportedLocales
:
return const MaterialApp(
title: 'Localizations Sample App',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
Locale('en', ''), // English, no country code
Locale('es', ''), // Spanish, no country code
],
home: MyHomePage(),
);