Annotation

Every generated widget starts with a class annotated with @HomeWidget(...). The annotation describes the widget's identity, its UI, and how it should be configured on each platform.

import 'package:home_widget_generator/home_widget_generator.dart';

@HomeWidget(
  name: 'Widget Configuration',
  description: 'A widget with configuration options',
  iOS: HomeWidgetIOSConfiguration(
    groupId: 'group.es.antonborri.hwGeneratePlayground',
    supportedFamilies: [
      HWWidgetFamily.systemSmall,
      HWWidgetFamily.systemMedium,
    ],
  ),
  android: HomeWidgetAndroidConfiguration(
    packageName: 'com.example',
    minWidth: 100,
    minHeight: 50,
    targetCellWidth: 2,
    targetCellHeight: 1,
    resizeMode: HWAndroidResizeMode.horizontal,
    widgetCategory: HWAndroidWidgetCategory.homeScreen,
    updatePeriodMillis: 3600000,
  ),
)
class ConfigurationOptions {}

@HomeWidget

ParameterTypeDefaultDescription
nameStringrequiredThe widget's name. Maps to the kind on iOS WidgetKit and the receiver label on Android.
descriptionString?nullDescription shown in the iOS and Android widget gallery.
widgetHWWidget?nullThe widget UI tree, built from the Widgets primitives.
dartOutputString?nullOverride the path of the generated Dart helper file.
androidHomeWidgetAndroidConfiguration?nullAndroid-specific configuration (see below).
iOSHomeWidgetIOSConfiguration?nulliOS-specific configuration (see below).
interactivityHomeWidgetInteractivityConfig?nullConfiguration for tap and intent-driven interactivity.

HomeWidgetAndroidConfiguration

Maps to AppWidgetProviderInfo on Android.

ParameterTypeDefaultDescription
packageNameString?auto-detectedApp package name. If omitted, the generator infers it from your Android project.
minWidthint?nullDefault width in dp. Maps to minWidth.
minHeightint?nullDefault height in dp. Maps to minHeight.
minResizeWidthint?nullMinimum resizable width in dp. Maps to minResizeWidth.
minResizeHeightint?nullMinimum resizable height in dp. Maps to minResizeHeight.
maxResizeWidthint?nullMaximum resizable width in dp (Android 12+). Maps to maxResizeWidth.
maxResizeHeightint?nullMaximum resizable height in dp (Android 12+). Maps to maxResizeHeight.
targetCellWidthint?nullDefault width in cells (Android 12+). Maps to targetCellWidth.
targetCellHeightint?nullDefault height in cells (Android 12+). Maps to targetCellHeight.
resizeModeHWAndroidResizeMode?nullHow the widget can be resized. Maps to resizeMode.
widgetCategoryHWAndroidWidgetCategory?nullWhere the widget can be shown. Maps to widgetCategory.
updatePeriodMillisint?nullRefresh interval in ms. Maps to updatePeriodMillis.
useGlanceThemebooltrueWraps the generated Glance UI in GlanceTheme { ... }.
backgroundColorHWColor?HWDefaultColor(HWColorRole.defaultBackground)Background color applied via GlanceModifier.background(...). See HWColor.
applyContentPaddingbooltrueApplies a default 16.dp root padding.
fillWidgetContentbooltrueApplies GlanceModifier.fillMaxSize() to the root.

HomeWidgetIOSConfiguration

Maps to WidgetConfiguration on iOS.

ParameterTypeDefaultDescription
groupIdStringrequiredApp Group ID used to share data between the app and the widget extension.
supportedFamiliesList<HWWidgetFamily>?all familiesRestricts which WidgetFamily values are supported. Maps to StaticConfiguration.supportedFamilies.
backgroundColorHWColor?nullBackground color for the widget container. See HWColor.
applyContentPaddingbooltrueIf false, calls contentMarginsDisabled() to opt out of system padding.