A Flutter UI component playground system with code generation support. This monorepo contains multiple packages that work together to create an interactive playground for testing and showcasing UI components.
| Package | Description |
|---|---|
| ui_playground | Flutter package providing the playground UI widget |
| ui_playground_annotations | Pure Dart package with annotations for code generation |
| ui_playground_generator | Code generator that creates playground items from annotations |
| ui_playground_example | Example app demonstrating the playground system |
┌─────────────────────────────────────────────────────────────────┐
│ ui_playground_example │
│ (Flutter app that uses the playground and generator) │
└─────────────────────────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌───────────────┐ ┌─────────────────┐ ┌─────────────────────┐
│ ui_playground │ │ ui_playground_ │ │ ui_playground_ │
│ (Flutter) │ │ annotations │ │ generator │
│ │ │ (Dart only) │ │ (Dart only) │
└───────────────┘ └─────────────────┘ └─────────────────────┘
│ ▲ │
│ │ │
└──────────────────────┴──────────────────────┘
(both depend on annotations)
- Add dependencies to your
pubspec.yaml:
dependencies:
ui_playground:
path: ../ui_playground
ui_playground_annotations:
path: ../ui_playground_annotations
dev_dependencies:
build_runner: ^2.4.9
ui_playground_generator:
path: ../ui_playground_generator- Create a simple trigger file:
// lib/ui_playground_items.dart
@UiPlaygroundComponents()
library;
import 'package:ui_playground/ui_playground.dart';- Annotate your widgets:
// lib/component/my_button.dart
import 'package:ui_playground/ui_playground.dart';
@UiPlaygroundComponent(title: 'My Button')
class MyButton extends StatelessWidget {
final String title;
final bool isEnabled;
const MyButton({required this.title, this.isEnabled = true, super.key});
@override
Widget build(BuildContext context) { ... }
}- Run the generator:
dart run build_runner build- Import and use the generated file:
import 'ui_playground_items.ui_playground.dart';
UiPlaygroundApp(
title: 'My App Playground',
sections: [
UiPlaygroundSection(
title: 'Buttons',
items: [
MyButtonPlaygroundItem(), // Generated automatically
],
),
],
)The generator automatically finds all @UiPlaygroundComponent widgets, generates all imports, and creates a complete standalone file.
# Get all dependencies
./tools/packages_get.sh
# Run code generation
./tools/build_runner_build.sh
# Format code
./tools/format.sh
# Analyze code
./tools/analyze.sh