widget_theme 0.1.4 copy "widget_theme: ^0.1.4" to clipboard
widget_theme: ^0.1.4 copied to clipboard

Code generation utilities for creating widget-specific theme models from Flutter widget properties, enabling scalable and consistent theming.

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:widget_theme_annotation/widget_theme_annotation.dart';

part 'main.g.dart';

@widgetTheme
class MyWidget extends StatelessWidget {
  const MyWidget({
    this.padding,
    this.color,
    super.key,
  });

  final Color? color;
  final EdgeInsets? padding;

  @override
  Widget build(BuildContext context) {
    final theme = MyWidgetTheme.of(context)._mergeWidget(this);

    return Padding(
      padding: theme.padding ?? const EdgeInsets.all(8),
      child: Text(
        'Hello world!',
        style: TextStyle(color: theme.color),
      ),
    );
  }
}

void main() => runApp(const MainApp());

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        extensions: const [
          MyWidgetTheme(color: Colors.red),
        ],
      ),
      home: const Scaffold(
        body: Center(child: MyWidget()),
      ),
    );
  }
}
0
likes
150
points
16
downloads

Documentation

API reference

Publisher

verified publisheralbinpk.dev

Weekly Downloads

Code generation utilities for creating widget-specific theme models from Flutter widget properties, enabling scalable and consistent theming.

Repository (GitHub)
View/report issues

Topics

#codegen #theming #flutter #ui #developer-tools

License

MIT (license)

Dependencies

analyzer, build, code_builder, dart_style, source_gen, widget_theme_annotation

More

Packages that depend on widget_theme