widget_kit
A small library for interfacing with the very limited parts of WidgetKit that are accessible through platform channels. API based on flutter_widgetkit. iOS and macOS only.
Introduction
The only parts of WidgetKit that can be accessed through Flutter are the following methods:
Method | Parameters | Description |
---|---|---|
reloadTimelines | ofKind | Reloads the timelines for all widgets of a particular kind. The ofKind parameter is an identifier that matches the value you used when creating the widget’s configuration. |
reloadAllTimelines | Reloads the timelines for all configured widgets belonging to the containing app. |
This means that this library is not for creating widget user interfaces. This library facilitates some interaction with WidgetKit timelines and basic means for passing arbitrary data to the underlying platform via UserDefaults and app groups. Retrieving that data and applying it to a Widget UI has to be done on the platform level; this is not possible through Flutter.
Usage
UserDefaults
import 'package:widget_kit/widget_kit.dart';
void foo() {
// Save some data to user preferences.
await UserDefaults.setString('key', 'value', 'group.tv.gameflow');
// Check if key is present.
await UserDefaults.contains('key'); // true
// Retrieve (typed) value.
await UserDefaults.getString('key'); // 'value'
// Remove pair.
await UserDefaults.remove('key'); // true
}
WidgetKit
// Reload all timelines
WidgetKit.reloadAllTimelines();
// Reload specific timeline
WidgetKit.reloadTimelines('foo');
Creating a Widget Extension
While this section is lacking written docs, check out the example app for a reference implementation.