I want to display today’s date in "Marathi" language.But the numbers from date are not displaying in Marathi language.
I have written following code lines to achieve it.
(flutter-3.0.4 stable)
DateTime currentDate = DateTime.now();
String todaysDate = DateFormat('d MMMM, yyyy', "mr_IN").format(currentDate);
Actual output is:
20 डिसेंबर, 2022
But I want to display:
२० डिसेंबर, २०२२
As we can see, numbers from date are not in Marathi language.
I have also wrote the below extension method but that also not resolve that issue:
extension ExtendedString on String {
String get toMarathi {
String dateInMarathi = this;
if (dateInMarathi.contains("0")) {
dateInMarathi = dateInMarathi.replaceAll("0", "०");
}
if (dateInMarathi.contains("1")) {
dateInMarathi = dateInMarathi.replaceAll("1", "१");
}
if (dateInMarathi.contains("2")) {
dateInMarathi = dateInMarathi.replaceAll("2", "२");
}
if (dateInMarathi.contains("3")) {
dateInMarathi = dateInMarathi.replaceAll("3", "३");
}
if (dateInMarathi.contains("4")) {
dateInMarathi = dateInMarathi.replaceAll("4", "४");
}
if (dateInMarathi.contains("5")) {
dateInMarathi = dateInMarathi.replaceAll("5", "५");
}
if (dateInMarathi.contains("6")) {
dateInMarathi = dateInMarathi.replaceAll("6", "६");
}
if (dateInMarathi.contains("7")) {
dateInMarathi = dateInMarathi.replaceAll("7", "७");
}
if (dateInMarathi.contains("8")) {
dateInMarathi = dateInMarathi.replaceAll("8", "८");
}
if (dateInMarathi.contains("9")) {
dateInMarathi = dateInMarathi.replaceAll("9", "९");
}
return dateInMarathi;
}
}
2
Answers
Try the following code:
Try below code refer some links GlobalMaterialLocalizations, initializeDateFormatting:
import below package for
add
initializeDateFormatting()
insideinitState
your date code
Your Widget:
Full Code:
Result->