Skip to content

Instantly share code, notes, and snippets.

@AlenaNicolay
Created August 8, 2023 12:26
Show Gist options
  • Save AlenaNicolay/2d2d3f2656a6f7eef7cab7dfdb534a5b to your computer and use it in GitHub Desktop.
Save AlenaNicolay/2d2d3f2656a6f7eef7cab7dfdb534a5b to your computer and use it in GitHub Desktop.
Annotate your Widgets
// lib/components/custom_button.dart
import 'package:flutter/material.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;
class CustomButton extends StatelessWidget {
const CustomButton({
super.key,
required this.title,
this.onPressed,
});
final String title;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
child: Text(title),
);
}
}
@widgetbook.UseCase(
name: 'Enabled',
type: CustomButton,
)
CustomButton enabledButton(BuildContext context) {
return CustomButton(
title: 'Enabled',
onPressed: () {},
);
}
@widgetbook.UseCase(
name: 'Disabled',
type: CustomButton,
)
CustomButton disabledButton(BuildContext context) {
return const CustomButton(
title: 'Disabled',
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment