---
title: Time-based Content
description: >-
  Schedule widget content to change automatically at specific points in time
  with HWTimedData.
---
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.page/abausg/home_widget/llms.txt
> Use this file to discover all available pages before exploring further.

# Time-based Content

Wrap any [`HWDataType`](/generator/data) with `HWTimedData` to have its value change automatically at specific points in time, without opening the app or running background code. This is the same idea weather and calendar apps use to show upcoming conditions or events ahead of time.

```dart
HWText(HWTimedData(HWString('label')))
HWText(HWTimedData(HWInt('temperature')))
HWText(HWTimedData(HWJson('weather', HWString('condition'))))
```

Any `HWDataType` variant can be wrapped, including `HWJson` and a runtime `HWImageData` — the nested value is read from the entry active at the current time, exactly like reading from regular storage otherwise.

<Warning>
`HWTimedData` only belongs at the root of a data field. It cannot be nested inside another `HWTimedData`, and it cannot sit inside an `HWJson` — write `HWTimedData(HWJson('weather', ...))`, never `HWJson('weather', HWTimedData(...))`.

A JSON root also takes a single `HWTimedData` declaration. To reach a deeper value, nest the paths inside that one declaration — `HWTimedData(HWJson('weather', HWJson('wind', HWInt('speed'))))` — rather than wrapping the same root twice.
</Warning>

## Example

```dart
import 'package:home_widget_generator/home_widget_generator.dart';

@HomeWidget(
  name: 'Weather',
  android: HomeWidgetAndroidConfiguration(packageName: 'com.example.app'),
  iOS: HomeWidgetIOSConfiguration(groupId: 'group.com.example.app'),
  widget: HWColumn(
    children: [
      HWText(HWString('location')),
      HWText(HWTimedData(HWString('label', defaultValue: 'Sunny'))),
      HWText(HWTimedData(HWInt('temperature'))),
      HWText(HWTimedData(HWJson('weather', HWString('condition')))),
    ],
  ),
)
class Weather {}
```

Alongside the usual `WeatherHomeWidget` helper, this generates a `WeatherTimedData` class with one nullable field per timed key. A wrapped `HWJson` gets a generated nested class, the same as for [regular JSON fields](/generator/data#nested-json):

```dart
class WeatherTimedData {
  final String? label;
  final int? temperature;
  final WeatherJsonData? weather;

  const WeatherTimedData({this.label, this.temperature, this.weather});
}
```

`saveData` gains a `timedData` parameter, keyed by the point in time each entry becomes active:

```dart
await WeatherHomeWidget.saveData(
  location: 'Berlin',
  timedData: {
    DateTime(2026, 8, 14, 6, 0): const WeatherTimedData(
      label: 'Sunny',
      temperature: 18,
      weather: WeatherJsonData(condition: 'sun'),
    ),
    DateTime(2026, 8, 14, 18, 0): const WeatherTimedData(
      label: 'Rainy',
      temperature: 12,
      weather: WeatherJsonData(condition: 'rain'),
    ),
  },
);
await WeatherHomeWidget.updateWidget();
```

<Info>
`saveData` only writes the schedule — always call `updateWidget()` afterwards. On iOS a widget keeps rendering the timeline it was last handed, so a freshly saved schedule is not picked up until `updateWidget()` (which calls `reloadTimelines`) runs, or until the previously built timeline runs out. On Android the alarms for the new times are armed by `saveData` itself, but the widget keeps showing the old content until it is updated.
</Info>

The whole map is written as a single JSON file (via the same `HomeWidget.saveFile` mechanism used for [nested JSON](/generator/data#nested-json)), keyed by epoch-millisecond UTC timestamps. `getData()` returns it back as `Map<DateTime, WeatherTimedData>?`, and `deleteData(timedData: true)` removes it.

The keys returned by `getData()` are **local-time** `DateTime`s, so they compare equal to a local `DateTime` for the same instant — a map that was saved with local keys round-trips with `containsKey`. Because timestamps are stored as epoch milliseconds, sub-millisecond precision of the keys is not preserved.

The widget gallery preview shows a single instant, resolved the same way as any other field: the
wrapped type's own `previewValue` (or `previewAsset`/`previewTranslations`), not a schedule. See
[Previews](/generator/previews).

## Resolution

At any point in time, the **active entry** is the one with the greatest timestamp at or before "now". Its values fill the timed fields for that moment. If a field is missing from the active entry, it falls back to that field's own `defaultValue`, then `null` — the same rule as regular data fields. If there is no entry at or before now (empty map, every entry still in the future, or nothing has been saved yet), every timed field uses its default. Entries never merge with one another — each one stands entirely on its own.

## Localized values

Timed values can be localized. Both flavours from [Localization](/generator/localization) work inside `HWTimedData` — a root field and a leaf of a wrapped `HWJson`:

```dart
HWText(HWTimedData(HWString.localized('label', defaultTranslations: {'en': 'Sunny', 'de': 'Sonnig'})))
HWText(HWTimedData(HWJson('weather', HWString.localized('condition', defaultTranslations: {'en': 'Sun', 'de': 'Sonne'}))))
```

A localized root field is stored **per locale inside each entry**, so its field on the generated timed data class is the widget's translations class rather than a `String`:

```dart
timedData: {
  DateTime(2026, 8, 14, 6, 0): const WeatherTimedData(
    label: WeatherHomeWidgetTranslations(en: 'Sunny', de: 'Sonnig'),
  ),
},
```

A localized JSON leaf behaves exactly like its untimed counterpart: the entry carries one plain string, and the leaf's `defaultTranslations` are what the widget falls back to when the path yields nothing.

Either way the text is resolved **at render time**, with the widget's normal fallback chain over the device's preferred languages — so a language change is picked up without saving a new schedule, and the entry active at that moment decides which set of translations is resolved. Anything an entry does not carry falls back to the translations compiled into the widget, one locale at a time, the same merge `getData()` performs.

## Images

A runtime [`HWImageData`](/generator/widgets/hw-image) can be timed too, so the widget swaps pictures on its own:

```dart
HWImage(HWTimedData(HWImageData('slide')))
```

The member on the generated timed data class is an `ImageProvider?`, not a `String?` — each entry carries the picture itself:

```dart
await WeatherHomeWidget.saveData(
  timedData: {
    DateTime(2026, 8, 14, 6, 0): const WeatherTimedData(
      slide: AssetImage('assets/morning.png'),
    ),
    DateTime(2026, 8, 14, 18, 0): const WeatherTimedData(
      slide: NetworkImage('https://example.com/evening.png'),
    ),
  },
);
```

`saveData` manages the pictures for you: saving a schedule keeps the images it needs and drops the ones no longer part of it, including for entries whose time has already passed but that are still in the schedule — the widget renders the active entry until a later one takes over. `deleteData(timedData: true)` removes the whole schedule together with all of its images. `getData()` hands each entry's image back as an `ImageProvider`.

<Warning>
`HWTimedData(HWImageData.asset(...))` is rejected at generation time: an asset ships inside the app and cannot change over time. Use `HWTimedData(HWImageData('key'))` and save one image per slot, or pick between bundled assets with a conditional. The same applies to an asset at a JSON leaf.
</Warning>

An image may equally sit at the leaf of a timed JSON group — `HWImage(HWTimedData(HWJson('slot', HWImageData('picture'))))`. The member on the generated `SlotJsonData` class is an `ImageProvider?`, and it belongs to its entry's timestamp exactly like a root timed image.

## Time-based lists

A [list](/generator/lists) is time-based when its item fields are read as `HWTimedData(HWItemData(...))`. Every entry then carries a whole list, and the builder renders the list of the active entry:

```dart
HWColumn.builder(
  'hourly',
  maxItems: 4,
  item: HWText.number(HWTimedData(HWItemData(HWInt('temperature')))),
  whenEmpty: HWText.fixed('No forecast yet'),
)
```

The list is a member of the generated timed data class, `final List<WeatherHourlyItem>? hourly;`, rather than a `saveData` parameter of its own. A list is time-based as a whole: every read of its item fields has to be timed, and `HWItemData(HWTimedData(...))` is rejected. With no active entry, an active entry without the list, or an empty list in it, the builder renders its `whenEmpty`. An image in an item belongs to its entry like the [images](#images) above: `saveData` writes one PNG per item and entry, and drops the pictures of the entries and items a new schedule no longer has. See [Time-based lists](/generator/lists#time-based-lists).

## Timezones and DST

Entry keys are **absolute instants**, not wall-clock times. Only the epoch milliseconds of each key are persisted, so a local `DateTime` and its `toUtc()` equivalent describe the exact same entry.

Nothing re-interprets a schedule when the device's clock rules change. A schedule that means "every morning at 06:00 local time" is computed once, at save time; after a DST switch or after the user travels into another timezone, those instants still fire at the moment they were computed for — which is now 05:00 or 07:00 local. If that drift matters, recompute the map and save it again (for example on app launch, or from a background refresh).

## How many entries

Keep the map modest — **tens of entries, not hundreds**. Every entry carries its own copy of the timed values (entries never merge), so the stored JSON grows with the entry count, and on iOS every future entry becomes a WidgetKit timeline entry that has to be built and held in memory when the timeline is requested. A day or two of hourly steps is a comfortable size; a full year of them is not. When the schedule runs out, the widget simply keeps showing the last entry until a new schedule is saved (iOS uses an `.atEnd` reload policy, so WidgetKit asks for a new timeline once the last entry is reached).

## Clearing

- Saving a **non-empty** `timedData` map replaces the whole schedule.
- Saving an **empty map**, or calling `deleteData(timedData: true)`, deletes the stored file and cancels the underlying schedule — see below.
- `timedData: null` (the default) leaves the existing schedule untouched, like every other `saveData` parameter.

## How it works per platform

<Accordion title="iOS">
The generated `TimelineProvider.getTimeline` loads every stored entry and builds a real WidgetKit timeline: one entry for "now" plus one for each entry timestamp still in the future, each resolved with the values active at its own time. WidgetKit swaps the displayed content at the right moments on its own — no app process, background task, or notification is involved. `getSnapshot` and the placeholder resolve a single entry for the current time.
</Accordion>

<Accordion title="Android">
There is no OS-level timeline API for home screen widgets on Android, so the generated helper schedules the swaps itself by calling `HomeWidget.scheduleWidgetUpdates` (see [Update Widget](/usage/update-widget#scheduled-updates) for the underlying plugin API and its exactness/permission caveats). Each time a scheduled update fires, the widget receives a normal broadcast update and the Glance content re-resolves the active entry for "now" from the same stored JSON — the generated `fromPreferences` gains a `now` parameter for this purpose.

Delivering those alarms requires `es.antonborri.home_widget.HomeWidgetScheduledUpdateReceiver` to be registered in your app's `AndroidManifest.xml`. **You do not have to add it yourself:** as soon as a widget schema uses `HWTimedData`, `home_widget_cli` adds the receiver and the `RECEIVE_BOOT_COMPLETED` permission to `android/app/src/main/AndroidManifest.xml` when it generates. The entry is added idempotently, and schemas without time-based data leave the manifest untouched. The resulting entry looks like this:

```xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application>
    <receiver
        android:name="es.antonborri.home_widget.HomeWidgetScheduledUpdateReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
            <action android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
        </intent-filter>
    </receiver>
</application>
```

The boot actions are what makes a schedule survive a reboot or an app update — alarms are dropped by the system in both cases and this receiver re-arms them. Alarms are also cleaned up automatically: once the last instance of a widget is removed from the home screen, its remaining scheduled updates are dropped.

On Android 12 and above the swaps only happen at the exact minute if the app holds an exact-alarm permission; otherwise they are scheduled inexactly and the system may delay them — if you notice entries switching minutes late on Android while iOS is on time, that is why, and [If updates arrive too late](/usage/update-widget#if-updates-arrive-too-late) walks through opting your app in to exact updates and the trade-offs of doing so. Use [`HomeWidget.canScheduleExactWidgetUpdates()`](/usage/update-widget#scheduled-updates) to find out which applies. If the user later revokes that permission, the system deletes the exact alarms outright and pauses the swaps; the same receiver re-arms them automatically once the permission is granted again (or on the next reboot) — see [Exact vs. inexact updates](/usage/update-widget#exact-vs-inexact-updates) for the platform details. Scheduling is a side effect of `saveData`: if it fails for any reason the data is still persisted, and `saveData` does not throw because of it.

</Accordion>
