Widget
Root widget container
The root of the widget tree. Build one with new Widget({...}) and hand it to Script.setWidget(). Widget.currentFamily and Widget.parameter let the layout adapt. The tap action is configured on the Home Screen, not here. A Link node takes priority inside its own area; tapping anywhere else runs the configured action.
Properties
currentFamilyWidgetFamily ›The current widget family: 'small', 'medium', 'large', etc.
parameterStringThe text typed into the widget's Parameter field, or passed as Parameter from Shortcuts. One free-text value per widget instance, so the same script on three widgets can show three different things. Null when unset. From Shortcuts this is the same string as Script.input.text.
sizeAnyThe widget's real point size.
Methods
Widget(config?)WidgetNodeThe root of the widget tree.
- config Any
- child WidgetNode
What the widget draws.
- supportedFamilies [WidgetFamily]
Which sizes this script offers. Every family by default.
- refreshInterval Duration
How often to ask for a redraw. iOS decides whether to grant it; five minutes is the floor.
- backgroundColor Color
A flat background.
- backgroundGradient LinearGradient
A gradient background. Wins over backgroundColor.
- padding EdgeInsets
Space between the edge and the child.
- child WidgetNode
Widget.requestReload()Request a widget timeline reload. Tells WidgetKit to re-run the script and refresh the widget display.
Examples
Adaptive widget
const family = Widget.currentFamily;
const isSmall = family === "small";
const content = isSmall
? Text("Compact")
: Column({ children: [
Text("Expanded"),
Text("More details here")
]});
const widget = new Widget({
backgroundColor: Color.hex("#1a1a2e"),
padding: EdgeInsets.all(16),
child: content
});
Script.setWidget(widget);