glance_widget_ios 2.0.1
glance_widget_ios: ^2.0.1 copied to clipboard
iOS implementation of the glance_widget plugin using WidgetKit.
Example #
This package is the iOS implementation of
glance_widget, and it is
endorsed:
depending on glance_widget pulls it in, and there is no separate API to call.
The runnable example is the one in the app-facing package —
glance_widget/example.
// Nothing here mentions this package. That is the point of endorsement.
import 'package:glance_widget/glance_widget.dart';
await GlanceWidget.updateSimpleWidget(
const SimpleWidgetData(
widgetId: 'crypto_btc',
title: 'Bitcoin',
value: r'$67,432',
subtitle: '+2.4%',
),
);
The Swift half of the example lives here #
Unlike Android, iOS cannot render a widget from a package: a widget extension is
a target in your Xcode project, so its SwiftUI has to be a file you own. The
templates you copy into it are in ios/GlanceWidgets/
next to this file — one Swift file per template, plus the shared models, the
widget-family helpers and the interactive-action plumbing they read.
Those files are not documentation that drifts. The example app's widget extension target compiles exactly these files, and so does its test target, so a renamed field breaks the build here before it reaches anybody's home screen.
Two things decide whether a copied template works at all, and both fail silently:
GlanceWidgetAppGroupmust name the same App Group in the app'sInfo.plistand the extension's. Two plists naming different groups gives you two working stores that are not the same store, and every update lands in the one nobody is reading.- iOS 17.0 is the minimum. The templates use
AppIntentConfiguration, which is the only widget configuration that carries a per-instance parameter — and therefore the only way a placed widget can know whichwidgetIdit is showing.
dart run glance_widget:doctor checks both without needing Xcode.