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 buildThe problem it solves
Adding a home screen widget to a Flutter app traditionally requires 5 concerns across 3 languages:
| What you need | Language | Where it lives |
|---|---|---|
| Widget layout | XML | android/app/src/main/res/layout/ |
| Widget metadata | XML | android/app/src/main/res/xml/ |
| Widget logic | Kotlin | android/app/src/main/kotlin/ |
| Widget registration | XML | AndroidManifest.xml |
| Data bridge | Dart + Kotlin | SharedPreferences |
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
- You declare an
AndroidWidgetin Dart with your layout and metadata build_runnerscanslib/and finds it- Generates XML layout, XML provider info, Kotlin
AppWidgetProvider, and manifest<receiver> flutter runcompiles 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 inWTextdisplay real-time data from Flutter - Button actions —
WButtonwith anactionKeytriggers an instant widget refresh - Multiple widgets — each top-level
AndroidWidgetvariable becomes its own home screen widget - 89 unit tests — the code generator is thoroughly tested
Version info
| Package version | 0.0.1 |
| Dart SDK | >=3.0.0 <4.0.0 |
| Flutter | >=3.10.0 |
| Platform | Android only (API 26+) |
Android only. Does not support iOS, web, or desktop.