我需要显示阿拉伯日期选择器
我需要显示一个阿拉伯日期选择器,我无法使用 Locale 构造函数控制它。 它仅显示英文视图。
选择日期方法
DateTime selectedDate = DateTime.now();
Future<void> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2000, 1),
lastDate: DateTime(2100),
builder: (BuildContext context, Widget child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: ColorScheme.light(primary: primaryColor)),
child: child,
);
});
if (picked != null && picked != selectedDate) {
selectedDate = picked;
}
}
主屏幕
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await GetStorage.init();
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
translations: Translation(),
locale: Locale(AuthController().appLocal.value),
fallbackLocale: Locale(AuthController().appLocal.value),
title: 'Hesabate App',
theme: ThemeData(
canvasColor: Colors.transparent,
fontFamily: "NotoNaskhArabic_font",
),
initialRoute: AppRoutes.splashScreen,
getPages: AppRoutes.routes,
);
}
}
我在此变量中有更新的语言(en&ar)
AuthController().appLocal.value
I need to display an Arabic date picker , I can't control this with Locale constructor .
It's only display an English view .
Pick date metod
DateTime selectedDate = DateTime.now();
Future<void> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2000, 1),
lastDate: DateTime(2100),
builder: (BuildContext context, Widget child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: ColorScheme.light(primary: primaryColor)),
child: child,
);
});
if (picked != null && picked != selectedDate) {
selectedDate = picked;
}
}
Main Screen
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await GetStorage.init();
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
translations: Translation(),
locale: Locale(AuthController().appLocal.value),
fallbackLocale: Locale(AuthController().appLocal.value),
title: 'Hesabate App',
theme: ThemeData(
canvasColor: Colors.transparent,
fontFamily: "NotoNaskhArabic_font",
),
initialRoute: AppRoutes.splashScreen,
getPages: AppRoutes.routes,
);
}
}
I have an updated language(en&ar) at this variable
AuthController().appLocal.value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢,我找到了我正在寻找的解决方案。
为了解决这个问题,我做了一些步骤:
1.在 pubspec.yaml 中添加 flutter_localizations 插件并运行 pub get。
2.在 dart 文件中导入插件
3.在 MaterialApp 中添加以下内容
4.然后实现默认的 datePicker,如下所示
5.最后将前面的方法调用到日期 TextField 中,如下所示
thank you , I found the solution I was looking for .
to solve the Issue , I did some steps :
1.Add flutter_localizations plugin in pubspec.yaml and run pub get.
2.Import the plugin in dart file
3.Inside MaterialApp, add following
4.then implement default datePicker as following
5.finally call the previous method into your date TextField as following
您能更具体地说明您正在使用哪个软件包吗?例如 flutter_datetime_picker 有参数 locale,您可以在其中传递 LocalType.ar
根据 Nader 澄清编辑,您可以将 locale:Locale("ar") 传递给内部 date_picker
Can you be more specific on which package you are using?. For example flutter_datetime_picker have parameter locale, where you can pass LocalType.ar
Edited per Nader clarification, you can pass locale:Locale("ar") to the internal date_picker
使用它对我有用 -
我的主要材质应用程序小部件中,我的主要外观 -
我们已经完成了一切都应该没问题
use this it worked for me -
for me my main looklike -
and we are done every thing should be ok