Data Types
HWDataType describes a single data field stored for a widget. You declare data fields in two places:
- Implicitly, by binding a widget to data (e.g.
HWText(HWInt('count'))). - Explicitly, via
HWDataOnlyorHWConditionalfor fields that aren't rendered directly.
Each variant carries a key (the storage key) and an optional defaultValue.
@HomeWidget(
name: 'Counter',
widget: HWText(HWInt('count', defaultValue: 0)),
android: HomeWidgetAndroidConfiguration(packageName: 'com.example.app'),
iOS: HomeWidgetIOSConfiguration(groupId: 'group.com.example.app'),
)
class CounterWidget {}
The generated Dart helper exposes typed setters for each declared field, e.g. setCount(42) / update(count: 42).
Variants
| Variant | Constructor | Dart type | Description |
|---|---|---|---|
HWString | HWString(key, {defaultValue}) | String | Stored as a string in SharedPreferences / UserDefaults. |
HWInt | HWInt(key, {defaultValue}) | int | Integer value. |
HWDouble | HWDouble(key, {defaultValue}) | double | Double / float value. |
HWBool | HWBool(key, {defaultValue}) | bool | Boolean value. |
HWJson | HWJson(key, child) | Map<String, dynamic> | Stored as a JSON string. Wraps another HWDataType to address a nested leaf (e.g. HWJson('user', HWString('name'))). |