Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The future of styling widgets (new package) #48

Open
ReinBentdal opened this issue Nov 26, 2019 · 5 comments
Open

The future of styling widgets (new package) #48

ReinBentdal opened this issue Nov 26, 2019 · 5 comments
Labels
Discussion Discussion related to project

Comments

@ReinBentdal
Copy link
Owner

I have made a new package called styled_widget which uses the new dart extension feature added in dart version 2.6.0. This is just an early concept.

GitHub: https://github.com/ReinBentdal/styled_widget
Pub: https://pub.dev/packages/styled_widget (Pub clearly didnt like dart version 2.6.0)

What do you think? Is there a future in styling widgets this way? If you like the concept or dont, let me know! Of course contributions are very welcome.

@moraispgsi
Copy link

moraispgsi commented Nov 26, 2019

The problem I see with this approach is that you cannot hoist/abstract the styling like you would in CSS. Maybe explore the decorator pattern for it, who knows.

@ReinBentdal
Copy link
Owner Author

ReinBentdal commented Nov 26, 2019

Yes its not possible to create style like in Division. I assume the flutter team wants us to use ThemeData to style general widgets. This only works for some general widgets like Card, AppBar, Button, etc, but maybe that is enough.

This could be a way to decouple style

final Styled textStyle = Styled.text()
  .backgroundColor(Colors.blue)

final Styled iconStyle = Styled.icon()
  .iconSize(24)
  .alignment(Alignment.center)

final Styled widgetStyle = Styled.widget()
  .bordeRadius(all: 10)

Widget build(BuildContext context) {
...
Text('some text').style(textStyle),
Icon(Icons.icon).style(iconStyle),
Container().style(widgetStyle)
...
}

@moraispgsi
Copy link

@ReinBentdal This looks like the way it is supposed to be. It is inviting for any React.js enthusiast.

@moraispgsi
Copy link

@ReinBentdal I would like to help you out in this direction, it looks promising. I don't have much time on my hands but I can help. Just lead the way.

@ReinBentdal ReinBentdal transferred this issue from ReinBentdal/division Nov 27, 2019
@ReinBentdal ReinBentdal transferred this issue from ReinBentdal/styled_widget Nov 27, 2019
@ReinBentdal ReinBentdal added the Discussion Discussion related to project label Nov 27, 2019
@ReinBentdal
Copy link
Owner Author

This is probably the easiest way to decouple style in my opinion

final styledWidget = (Widget child) => Styled.widget(child)
  .backgroundColor(Colors.blue)
  .constraints(width: 100, height: 100)
  .borderRadius(all: 10)
  .elevation(10)
  .alignment(Alignment.center);

This makes to coding part much easier as well

extension Styled on Widget {
  static Widget widget([Widget child]) => ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Discussion related to project
Projects
None yet
Development

No branches or pull requests

2 participants