tryLocalizeDate method

String? tryLocalizeDate(
  1. DateTime? date,
  2. String pattern
)

Parses the given date and returns the localized version of the date based on the given pattern.

Uses the underlying date localize use case provided by dateLocalizeUseCaseProvider within the surrounding provider scope.

Returns null if the given date is null.

Implementation

String? tryLocalizeDate(DateTime? date, String pattern) {
  final localizeDate =
      ProviderScope.containerOf(this).read(dateLocalizeUseCaseProvider);
  final locale = Localizations.maybeLocaleOf(this)?.toLanguageTag();

  if (date == null) return null;

  return localizeDate(date, pattern, locale);
}