getters method
mark these functions as protected as we need the implementations, but discourage direct usages. Reasons:
- There are more base getters/setters/methods from the base class. Users can just focus on defining only applicable fields for their classes but still get the base implementations automatically.
- setProperty() will automatically notify the controller's listeners for changes, enabling the listeners (widget state) to redraw.
Use getProperty/setProperty/callMethod instead of these.
Implementation
Map<String, Function> getters() {
return {
'time': () => dateTime.toLocal().millisecondsSinceEpoch,
'year': () => dateTime.toLocal().year,
'month': () =>
dateTime.toLocal().month - 1, // JavaScript months are zero-based
'day': () => dateTime.toLocal().day,
'weekday': () =>
dateTime.toLocal().weekday % 7, // JavaScript days are zero-based
'hour': () => dateTime.toLocal().hour,
'minute': () => dateTime.toLocal().minute,
'second': () => dateTime.toLocal().second,
'millisecond': () => dateTime.toLocal().millisecond,
'timezoneOffset': () => -dateTime.timeZoneOffset.inMinutes,
'isoString': () => dateTime.toUtc().toIso8601String(),
'localDateString': () => dateTime.toLocal().toString().split(' ')[0],
'localTimeString': () =>
dateTime.toLocal().toString().split(' ')[1].split('.')[0],
'localString': () => dateTime.toLocal().toString().split('.')[0],
'utcFullYear': () => dateTime.toUtc().year,
'utcMonth': () =>
dateTime.toUtc().month - 1, // JavaScript months are zero-based
'utcDate': () => dateTime.toUtc().day,
'utcDay': () =>
dateTime.toUtc().weekday % 7, // JavaScript days are zero-based
'utcHours': () => dateTime.toUtc().hour,
'utcMinutes': () => dateTime.toUtc().minute,
'utcSeconds': () => dateTime.toUtc().second,
'utcMilliseconds': () => dateTime.toUtc().millisecond,
};
}