doc_widget
0.4.0, released 4 years ago by isacjunior.dev
Generates documentation for Flutter widgets via annotations and a preview app.
What it does
The package provides an annotation to mark widgets for documentation. A build_runner code generator creates files describing widget parameters, snippets, and metadata, which can be displayed in a preview application.
AI-written summary of version 0.4.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want automatically generated docs for a library of custom widgets.
- You need a quick way to preview widget usage examples without writing manual docs.
Skip it when
- You prefer runtime reflection or manual documentation.
- Your project cannot add a build step or extra dependencies.
Strengths
- Zero‑manual doc writing – generated from code.
- Integrated preview UI for desktop, web, and mobile.
- Supports null‑safety and default values.
Weaknesses
- Requires build_runner and a separate builder package.
- Only works for Flutter widgets, not pure Dart code.
- Adds extra generated files to the repo.
Setup
- Kind
- Flutter widgets
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 2
Add doc_widget and doc_widget_builder to dependencies, include build_runner in dev_dependencies, then run flutter pub run build_runner build to generate docs.
@docWidget
class Button extends StatelessWidget {
Button(this.text, {required this.onPressed, this.color = const Color(0xff007aff)});
final String text;
final void Function() onPressed;
final Color color;
@override
Widget build(BuildContext context) => CupertinoButton(color: color, onPressed: onPressed, child: Text(text));
}
// Then run:
// flutter pub run build_runner buildAlternatives
Packages that do the same job and could replace doc_widget.
- pigeon
Type-safe code generator for communication between Flutter and host platforms.
90Compare - checked_yaml
Provides checkedYamlDecode to give detailed errors when decoding YAML with json_serializable.
79Compare - gql_code_builder
Dart code builder generating typed classes from GraphQL documents and SDL
78Compare - envify
Handle environment variables safely using .env files and code generation.
48Compare
Works with
Packages commonly used together with doc_widget: ones it builds on, ones built on it, and its own family.