Reputation: 1025
I would like to get all the names of each week day translated so I can displayed them, but I can't figure out how to do it.
I know how to get a localized week day name for a particular date with: DateTime(...).format('E')
but that's not what I want.
Ideally I would do something like this:
var localizedWeekDays = getLocalizedWeekDays('en_US');
print(localizedWeekDays);
// ['Sunday', 'Monday', 'Tuesday', ...]
Any ideas?
Upvotes: 1
Views: 1036
Reputation: 21
in your pubspec.yaml file, dependencies section. add intl dependency
dependencies:
intl: ^0.17.0
add then import the package
import 'package:intl/intl.dart';
to get all localized weekdays
final weekdays = DateFormat().dateSymbols.WEEKDAYS;
// [Sunday, Monday, ...]
There are many more options available: https://api.flutter.dev/flutter/date_symbols/DateSymbols-class.html
Upvotes: 2