Skip to content

Commit b2c6fd2

Browse files
blueneogeogitbook-bot
authored andcommitted
GitBook: [master] one page modified
1 parent 6c4784a commit b2c6fd2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

guide/styling-with-css.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,37 @@ Card ArtistCard({ @required onBuyPressed, @required onListenPressed }) {
279279

280280
As you can see here, Sass is a nice match with Pug, since you can retain the same structure. This makes it easy to find the matching styles to your pug elements.
281281

282+
## Using Flutter Themes in styles
283+
284+
Flutter's Material library has [theming support](https://flutter.io/docs/cookbook/design/themes). You may want to assign the values of the theme of the current BuildContext. Flutter-view has support for easily assigning [**ThemeData**](https://docs.flutter.io/flutter/material/ThemeData-class.html) values to your properties.
285+
286+
To understand how it works, let's first look at how you would use it in pure Dart code. To assign a font size to a style, you may write something like this:
287+
288+
```dart
289+
style: TextStyle(
290+
fontSize: Theme.of(context).textTheme.title.fontSize,
291+
)
292+
```
293+
294+
First we find the Theme of the current [**BuildContext**](https://docs.flutter.io/flutter/widgets/BuildContext-class.html), then we get a path of properties.
295+
296+
In flutter-view CSS, you might write this the same way:
297+
298+
```css
299+
.foo
300+
font-size: ':Theme.of(context).textTheme.title.fontSize'
301+
```
302+
303+
Instead, you may write it like this:
304+
305+
```css
306+
.foo
307+
font-size: theme(text-theme/title/font-size)
308+
```
309+
310+
This still requires the context to be available. If you have no current context, you can use the [**builder shortcut**](../reference/tag-shortcuts.md#builder). The theme properties path has been replaced by dash-cased steps, separated by forward slashes`/`.
311+
312+
_Pro tip: You can define CSS classes that set multiple theme style properties at once and reuse them across your app._
313+
314+
315+

0 commit comments

Comments
 (0)