Created
May 10, 2022 12:09
-
-
Save lesnitsky/5e47f083e91cff14b7039566325314c3 to your computer and use it in GitHub Desktop.
Styled widget concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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