flutter_android_widgets

Introduction

flutter_android_widgets is a Dart-first code generation package that lets you define Android home screen widgets using nothing but Dart.

No XML layout files. No Kotlin provider classes. No manual AndroidManifest.xml edits. Write a single Dart declaration and run build_runner — the package generates everything.

final myWidget = AndroidWidget(
  info: WidgetInfo(
    widgetClassName: 'MyWidgetProvider',
    widgetName: 'My Widget',
    minWidth: 250,
    minHeight: 100,
    updateInterval: Duration(hours: 1),
  ),
  layout: WColumn(
    backgroundColor: '#1A1A2E',
    padding: 16,
    children: [
      WText('\${userName}', textSize: 18, bold: true, textColor: '#FFFFFF'),
      WText('\${lastUpdated}', textSize: 12, textColor: '#AAAAAA'),
      WButton(label: 'Refresh', actionKey: 'refresh'),
    ],
  ),
  dataKeys: ['userName', 'lastUpdated'],
);

Run one command, get four native files:

dart run build_runner build

The problem it solves

Adding a home screen widget to a Flutter app traditionally requires 5 concerns across 3 languages:

What you needLanguageWhere it lives
Widget layoutXMLandroid/app/src/main/res/layout/
Widget metadataXMLandroid/app/src/main/res/xml/
Widget logicKotlinandroid/app/src/main/kotlin/
Widget registrationXMLAndroidManifest.xml
Data bridgeDart + KotlinSharedPreferences

Miss one and the widget silently fails. Change the layout and you must update the XML, the Kotlin, and the manifest — in lockstep, by hand. This package eliminates that entirely.


How it works

  1. You declare an AndroidWidget in Dart with your layout and metadata
  2. build_runner scans lib/ and finds it
  3. Generates XML layout, XML provider info, Kotlin AppWidgetProvider, and manifest <receiver>
  4. flutter run compiles and deploys everything

The Dart definition is the single source of truth — change it, re-run build_runner, and all four native files update together.


Key features

  • Zero native code — just Dart and build_runner
  • Live styling — colors, sizes, and padding update via hot restart without rebuilding the APK
  • Data binding\${key} placeholders in WText display real-time data from Flutter
  • Button actionsWButton with an actionKey triggers an instant widget refresh
  • Multiple widgets — each top-level AndroidWidget variable becomes its own home screen widget
  • 89 unit tests — the code generator is thoroughly tested

Version info

Package version0.0.1
Dart SDK>=3.0.0 <4.0.0
Flutter>=3.10.0
PlatformAndroid only (API 26+)

Android only. Does not support iOS, web, or desktop.

On this page

No Headings