widget_kit_plugin 0.1.1 copy "widget_kit_plugin: ^0.1.1" to clipboard
widget_kit_plugin: ^0.1.1 copied to clipboard

PlatformiOSmacOS

A library for interfacing with a small subset of the WidgetKit API.

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.

UserDefaults is used as data can be shared across the iOS app and the widget extension with the use of app groups. This way, data can be set from the main application (Dart) and retrieved in the widget extension (Swift). Again, presentation logic has to be written using Swift/SwiftUI.

Usage #

UserDefaults #

import 'package:widget_kit_plugin/widget_kit_plugin.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 #

import 'package:widget_kit_plugin/widget_kit_plugin.dart';

void bar() {
  // Reload all timelines
  await WidgetKit.reloadAllTimelines();

  // Reload specific timeline
  await WidgetKit.reloadTimelines('foo');
}

Creating a Widget Extension #

TODO(arnemolland): document widget extension process

While this section is lacking written docs, check out the example app for a reference implementation.

6
likes
130
pub points
81%
popularity
screenshot

Publisher

verified publishergameflow.tv

A library for interfacing with a small subset of the WidgetKit API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on widget_kit_plugin