Skip to content

Instantly share code, notes, and snippets.

@lesnitsky
Created May 10, 2022 12:09
Show Gist options
  • Save lesnitsky/5e47f083e91cff14b7039566325314c3 to your computer and use it in GitHub Desktop.
Save lesnitsky/5e47f083e91cff14b7039566325314c3 to your computer and use it in GitHub Desktop.
Styled widget concept
part 'my_widget.styled.dart'; // generated code here
// below is what user writes
@Style()
// ^^^^ provided by the library
class WidgetStyle {
const WidgetStyle();
final EdgeInsets padding => const EdgeInsets.all(8.0);
}
@Styled<WidgetStyle>
// ^^^ provided by the library
class MyWidget extends StatelessWidget {
Widget build(BuildContext context) {
final WidgetStyle style = context.stylesOf(this);
// ^^^^^^^^ this will be provided by the library
return Padding(
padding: styles.padding,
child: Text('hello world'),
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment