I’m trying to create a design system, which a button can have a custom variant, and depending on that variant it’ll have a corresponding default text style, which could be overridden if needed. For example
class MyText extends StatelessWidget{
final String text;
final MyFontSize fontSize;
...
MyText copyWith({MyFontSize? fontSize}) {
...
}
}
class MyButton extends StatelessWidget {
final MyText text;
final MytButtonVariant variant;
build() {
final text = this.text.merge(
fontSize: _fontSizeFromVariant(variant)
);
return ElevatedButton(child: text, ...)
}
}
My colleague makes the argument that we should move the MyFontSize & all the other params into an object, MyTextStyle, and the MyButton will take in String text & MyTextStyle style as the params, and perform copyWith/merge on the MyTextStyle, similar to how the Text widget and the TextStyle.
The main difference between MyButton and ElevatedButton is it doesn’t take in any widget, but only MyText, so it justifies for the unusual copyWith in Widget.
What do you think?