| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- // Copyright 2017 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- import 'dart:async';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/widgets.dart';
- /// Determines the order of the columns inside [CupertinoDatePicker] in
- /// time and date time mode.
- enum DatePickerDateTimeOrder {
- /// Order of the columns, from left to right: date, hour, minute, am/pm.
- ///
- /// Example: [Fri Aug 31 | 02 | 08 | PM].
- date_time_dayPeriod,
- /// Order of the columns, from left to right: date, am/pm, hour, minute.
- ///
- /// Example: [Fri Aug 31 | PM | 02 | 08].
- date_dayPeriod_time,
- /// Order of the columns, from left to right: hour, minute, am/pm, date.
- ///
- /// Example: [02 | 08 | PM | Fri Aug 31].
- time_dayPeriod_date,
- /// Order of the columns, from left to right: am/pm, hour, minute, date.
- ///
- /// Example: [PM | 02 | 08 | Fri Aug 31].
- dayPeriod_time_date,
- }
- /// Determines the order of the columns inside [CupertinoDatePicker] in date mode.
- enum DatePickerDateOrder {
- /// Order of the columns, from left to right: day, month, year.
- ///
- /// Example: [12 | March | 1996]
- dmy,
- /// Order of the columns, from left to right: month, day, year.
- ///
- /// Example: [March | 12 | 1996]
- mdy,
- /// Order of the columns, from left to right: year, month, day.
- ///
- /// Example: [1996 | March | 12]
- ymd,
- /// Order of the columns, from left to right: year, day, month.
- ///
- /// Example: [1996 | 12 | March]
- ydm,
- }
- /// Defines the localized resource values used by the Cupertino widgets.
- ///
- /// See also:
- ///
- /// * [DefaultCupertinoLocalizations], the default, English-only, implementation
- /// of this interface.
- // TODO(xster): Supply non-english strings.
- abstract class CupertinoLocalizations {
- /// Year that is shown in [CupertinoDatePicker] spinner corresponding to the
- /// given year index.
- ///
- /// Examples: datePickerYear(1) in:
- ///
- /// - US English: 2018
- /// - Korean: 2018년
- String datePickerYear(int yearIndex);
- /// Month that is shown in [CupertinoDatePicker] spinner corresponding to
- /// the given month index.
- ///
- /// Examples: datePickerMonth(1) in:
- ///
- /// - US English: January
- /// - Korean: 1월
- String datePickerMonth(int monthIndex);
- /// Day of month that is shown in [CupertinoDatePicker] spinner corresponding
- /// to the given day index.
- ///
- /// Examples: datePickerDayOfMonth(1) in:
- ///
- /// - US English: 1
- /// - Korean: 1일
- String datePickerDayOfMonth(int dayIndex);
- /// The medium-width date format that is shown in [CupertinoDatePicker]
- /// spinner. Abbreviates month and days of week.
- ///
- /// Examples:
- ///
- /// - US English: Wed Sep 27
- /// - Russian: ср сент. 27
- String datePickerMediumDate(DateTime date);
- /// Hour that is shown in [CupertinoDatePicker] spinner corresponding
- /// to the given hour value.
- ///
- /// Examples: datePickerHour(1) in:
- ///
- /// - US English: 1
- /// - Arabic: ٠١
- String datePickerHour(int hour);
- /// Semantics label for the given hour value in [CupertinoDatePicker].
- String datePickerHourSemanticsLabel(int hour);
- /// Minute that is shown in [CupertinoDatePicker] spinner corresponding
- /// to the given minute value.
- ///
- /// Examples: datePickerMinute(1) in:
- ///
- /// - US English: 01
- /// - Arabic: ٠١
- String datePickerMinute(int minute);
- /// Semantics label for the given minute value in [CupertinoDatePicker].
- String datePickerMinuteSemanticsLabel(int minute);
- /// The order of the date elements that will be shown in [CupertinoDatePicker].
- DatePickerDateOrder get datePickerDateOrder;
- /// The order of the time elements that will be shown in [CupertinoDatePicker].
- DatePickerDateTimeOrder get datePickerDateTimeOrder;
- /// The abbreviation for ante meridiem (before noon) shown in the time picker.
- String get anteMeridiemAbbreviation;
- /// The abbreviation for post meridiem (after noon) shown in the time picker.
- String get postMeridiemAbbreviation;
- /// The term used by the system to announce dialog alerts.
- String get alertDialogLabel;
- /// Hour that is shown in [CupertinoCountdownTimerPicker] corresponding to
- /// the given hour value.
- ///
- /// Examples: timerPickerHour(1) in:
- ///
- /// - US English: 1
- /// - Arabic: ١
- String timerPickerHour(int hour);
- /// Minute that is shown in [CupertinoCountdownTimerPicker] corresponding to
- /// the given minute value.
- ///
- /// Examples: timerPickerMinute(1) in:
- ///
- /// - US English: 1
- /// - Arabic: ١
- String timerPickerMinute(int minute);
- /// Second that is shown in [CupertinoCountdownTimerPicker] corresponding to
- /// the given second value.
- ///
- /// Examples: timerPickerSecond(1) in:
- ///
- /// - US English: 1
- /// - Arabic: ١
- String timerPickerSecond(int second);
- /// Label that appears next to the hour picker in
- /// [CupertinoCountdownTimerPicker] when selected hour value is `hour`.
- /// This function will deal with pluralization based on the `hour` parameter.
- String timerPickerHourLabel(int hour);
- /// Label that appears next to the minute picker in
- /// [CupertinoCountdownTimerPicker] when selected minute value is `minute`.
- /// This function will deal with pluralization based on the `minute` parameter.
- String timerPickerMinuteLabel(int minute);
- /// Label that appears next to the minute picker in
- /// [CupertinoCountdownTimerPicker] when selected minute value is `second`.
- /// This function will deal with pluralization based on the `second` parameter.
- String timerPickerSecondLabel(int second);
- /// The term used for cutting
- String get cutButtonLabel;
- /// The term used for copying
- String get copyButtonLabel;
- /// The term used for pasting
- String get pasteButtonLabel;
- /// The term used for selecting everything
- String get selectAllButtonLabel;
- /// The `CupertinoLocalizations` from the closest [Localizations] instance
- /// that encloses the given context.
- ///
- /// This method is just a convenient shorthand for:
- /// `Localizations.of<CupertinoLocalizations>(context, CupertinoLocalizations)`.
- ///
- /// References to the localized resources defined by this class are typically
- /// written in terms of this method. For example:
- ///
- /// ```dart
- /// CupertinoLocalizations.of(context).anteMeridiemAbbreviation;
- /// ```
- static CupertinoLocalizations of(BuildContext context) {
- return Localizations.of<CupertinoLocalizations>(context, CupertinoLocalizations);
- }
- }
- class _CupertinoLocalizationsDelegate extends LocalizationsDelegate<CupertinoLocalizations> {
- const _CupertinoLocalizationsDelegate();
- @override
- bool isSupported(Locale locale) => locale.languageCode == 'en';
- @override
- Future<CupertinoLocalizations> load(Locale locale) => DefaultCupertinoLocalizations.load(locale);
- @override
- bool shouldReload(_CupertinoLocalizationsDelegate old) => false;
- @override
- String toString() => 'DefaultCupertinoLocalizations.delegate(en_US)';
- }
- /// US English strings for the cupertino widgets.
- class DefaultCupertinoLocalizations implements CupertinoLocalizations {
- /// Constructs an object that defines the cupertino widgets' localized strings
- /// for US English (only).
- ///
- /// [LocalizationsDelegate] implementations typically call the static [load]
- /// function, rather than constructing this class directly.
- const DefaultCupertinoLocalizations();
- static const List<String> _shortWeekdays = <String>[
- 'Mon',
- 'Tue',
- 'Wed',
- 'Thu',
- 'Fri',
- 'Sat',
- 'Sun',
- ];
- static const List<String> _shortMonths = <String>[
- 'Jan',
- 'Feb',
- 'Mar',
- 'Apr',
- 'May',
- 'Jun',
- 'Jul',
- 'Aug',
- 'Sep',
- 'Oct',
- 'Nov',
- 'Dec',
- ];
- static const List<String> _months = <String>[
- 'January',
- 'February',
- 'March',
- 'April',
- 'May',
- 'June',
- 'July',
- 'August',
- 'September',
- 'October',
- 'November',
- 'December',
- ];
- @override
- String datePickerYear(int yearIndex) => yearIndex.toString();
- @override
- String datePickerMonth(int monthIndex) => _months[monthIndex - 1];
- @override
- String datePickerDayOfMonth(int dayIndex) => dayIndex.toString();
- @override
- String datePickerHour(int hour) => hour.toString();
- @override
- String datePickerHourSemanticsLabel(int hour) => hour.toString() + " o'clock";
- @override
- String datePickerMinute(int minute) => minute.toString().padLeft(2, '0');
- @override
- String datePickerMinuteSemanticsLabel(int minute) {
- if (minute == 1)
- return '1 minute';
- return minute.toString() + ' minutes';
- }
- @override
- String datePickerMediumDate(DateTime date) {
- return '${_shortWeekdays[date.weekday - DateTime.monday]} '
- '${_shortMonths[date.month - DateTime.january]} '
- '${date.day.toString().padRight(2)}';
- }
- @override
- DatePickerDateOrder get datePickerDateOrder => DatePickerDateOrder.mdy;
- @override
- DatePickerDateTimeOrder get datePickerDateTimeOrder => DatePickerDateTimeOrder.date_time_dayPeriod;
- @override
- String get anteMeridiemAbbreviation => 'AM';
- @override
- String get postMeridiemAbbreviation => 'PM';
- @override
- String get alertDialogLabel => 'Alert';
- @override
- String timerPickerHour(int hour) => hour.toString();
- @override
- String timerPickerMinute(int minute) => minute.toString();
- @override
- String timerPickerSecond(int second) => second.toString();
- @override
- String timerPickerHourLabel(int hour) => hour == 1 ? 'hour' : 'hours';
- @override
- String timerPickerMinuteLabel(int minute) => 'min';
- @override
- String timerPickerSecondLabel(int second) => 'sec';
- @override
- String get cutButtonLabel => 'Cut';
- @override
- String get copyButtonLabel => 'Copy';
- @override
- String get pasteButtonLabel => 'Paste';
- @override
- String get selectAllButtonLabel => 'Select All';
- /// Creates an object that provides US English resource values for the
- /// cupertino library widgets.
- ///
- /// The [locale] parameter is ignored.
- ///
- /// This method is typically used to create a [LocalizationsDelegate].
- static Future<CupertinoLocalizations> load(Locale locale) {
- return SynchronousFuture<CupertinoLocalizations>(const DefaultCupertinoLocalizations());
- }
- /// A [LocalizationsDelegate] that uses [DefaultCupertinoLocalizations.load]
- /// to create an instance of this class.
- static const LocalizationsDelegate<CupertinoLocalizations> delegate = _CupertinoLocalizationsDelegate();
- }
|