initializeDateFormatting function
This should be called for at least one locale
before any date formatting
methods are called. It sets up the lookup for date symbols using url
.
The url
parameter should end with a "/". For example,
"http://localhost:8000/dates/"
Implementation
Future<void> initializeDateFormatting(String locale, String url) {
//Initialize symbols
var symbolReader = HttpRequestDataReader('${url}symbols/');
LazyLocaleData symbolsInitializer() => LazyLocaleData(
symbolReader,
_createDateSymbol,
availableLocalesForDateFormatting,
);
initializeDateSymbols(symbolsInitializer);
//Initialize patterns
var patternsReader = HttpRequestDataReader('${url}patterns/');
LazyLocaleData patternsInitializer() => LazyLocaleData(
patternsReader,
(x) => x,
availableLocalesForDateFormatting,
);
initializeDatePatterns(patternsInitializer);
var actualLocale = Intl.verifiedLocale(
locale,
availableLocalesForDateFormatting.contains,
)!;
//Initialize locale for both symbols and patterns
Future<List<void>> initLocale(
LazyLocaleData symbols,
LazyLocaleData patterns,
) {
return Future.wait([
symbols.initLocale(actualLocale),
patterns.initLocale(actualLocale),
]);
}
return initializeIndividualLocaleDateFormatting(initLocale);
}