home_widget_generator 0.0.1 copy "home_widget_generator: ^0.0.1" to clipboard
home_widget_generator: ^0.0.1 copied to clipboard

Annotations and DSL widgets to generate native HomeScreen widget code for the home_widget Flutter plugin.

home_widget_generator #

Pub likes pub points GitHub-sponsors

Describe a HomeScreen widget once in Dart and have the matching native widget code generated for you. Instead of writing SwiftUI and Jetpack Glance by hand, you author a small annotated Dart class.

This package provides the @HomeWidget annotation and the DSL widgets (HWColumn, HWText, ...) used to describe the UI. The code generation itself is performed by the companion home_widget_cli tool, and the generated widget continues to be driven at runtime by home_widget.

Documentation #

Read the full reference, including all annotation options, layout primitives, and styling helpers, on docs.page.

Installation #

Add this package and home_widget_cli as dev dependencies, and home_widget as a runtime dependency:

dependencies:
  home_widget: ^0.9.0

dev_dependencies:
  home_widget_generator: ^0.0.1
  home_widget_cli: ^0.0.1

Usage #

Define a widget schema in home_widget/greeting.dart:

import 'package:home_widget_generator/home_widget_generator.dart';

@HomeWidget(
  name: 'Greeting',
  android: HomeWidgetAndroidConfiguration(),
  iOS: HomeWidgetIOSConfiguration(
    groupId: 'group.com.example.app',
  ),
  widget: HWColumn(
    crossAxisAlignment: HWCrossAxisAlignment.start,
    children: [
      HWText.fixed(
        'Hello',
        style: HWRoleTextStyle(role: HWTextStyleRole.caption),
      ),
      HWText(
        HWString('name', defaultValue: 'world'),
        style: HWRoleTextStyle(
          role: HWTextStyleRole.title,
          fontWeight: HWFontWeight.bold,
        ),
      ),
    ],
  ),
)
class Greeting {}

Run the CLI to generate the iOS, Android, and Dart helper sources:

dart run home_widget_cli generate

Then drive the widget from your app:

import 'src/home_widget/greeting.home_widget.dart';

await GreetingHomeWidget.saveData(name: 'Anton');
await GreetingHomeWidget.updateWidget();

See the Getting Started guide for a full walkthrough.

Examples #

Screenshots from the generator_basics example app (install name: home_widget_generator). Each row is one @HomeWidget name as shown in the iOS and Android widget pickers.

Name iOS Android
Greeting
Basic Creation
Adaptive Greeting
Themed Counter
Simple Data
Conditional Status

See more examples with full @HomeWidget source in the example README. Runnable schemas and a demo app live in examples/generator_basics.

Sponsors #

I develop this package in my free time. If you or your company benefits from home_widget, it would mean a lot to me if you considered supporting me on GitHub Sponsors

Github Sponsors of ABausG

1
likes
150
points
0
downloads

Documentation

Documentation
API reference

Publisher

verified publisherantonborri.es

Weekly Downloads

Annotations and DSL widgets to generate native HomeScreen widget code for the home_widget Flutter plugin.

Repository (GitHub)
View/report issues

Topics

#home-screen-widget #code-generation #android #ios #home-widget

Funding

Consider supporting this project:

github.com

License

BSD-3-Clause (license)

Dependencies

analyzer, home_widget

More

Packages that depend on home_widget_generator