Skip to content

Commit 56d6f4b

Browse files
blueneogeogitbook-bot
authored andcommitted
GitBook: [master] 5 pages modified
1 parent 71e7715 commit 56d6f4b

File tree

5 files changed

+85
-47
lines changed

5 files changed

+85
-47
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ Container Hello() {
5757
{% endtab %}
5858
{% endtabs %}
5959

60+
_Click the tabs to see the Pug code, the HTML representation of the Pug, and the Dart code that flutter-view generates for you._
61+
6062
This generated function can be used like any other Dart code, and will return the code that gives the greeting.
6163

6264
## Adding Styling
6365

64-
You can add Sass/CSS to styles to your view. Flutter-view contains [shortcut properties](reference/css-properties.md) that take your CSS-like properties and convert them into code. For our example, you can easily add a text [**color**](reference/css-properties.md#color-color), [**background color**](reference/css-properties.md#box-shadow-2), some [**font properties**](reference/css-properties.md#box-shadow-8), and add [**padding**](reference/css-properties.md#padding):
66+
You can add Sass/CSS to styles to your view. Flutter-view supports [CSS style properties](reference/css-properties.md) that convert into code. For our example, you can easily add a text [**color**](reference/css-properties.md#color-color), [**background color**](reference/css-properties.md#box-shadow-2), some [**font properties**](reference/css-properties.md#box-shadow-8), and add [**padding**](reference/css-properties.md#padding):
6567

6668
{% tabs %}
6769
{% tab title="Pug" %}
@@ -118,6 +120,8 @@ Hello() {
118120
{% endtab %}
119121
{% endtabs %}
120122

123+
_Click the tabs to see the Pug code, the Sass styles we apply, and the code that flutter-view generates for you._
124+
121125
Flutter-view supports [many CSS properties](reference/css-properties.md), and makes it easy to change styles and immediately see the effect. Since single CSS rules can apply to many elements, small CSS changes may have big code effects.
122126

123127
You can also fully leverage both Pug and Sass mixin and function support, allowing for some powerful patters, such as [different styling based on running Android or iOS](guide/untitled.md).

SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424

2525
## Shortcuts Reference <a id="reference"></a>
2626

27-
* [Pug tag shortcuts](reference/tag-shortcuts.md)
28-
* [CSS style shortcuts](reference/css-properties.md)
27+
* [Special pug tags](reference/tag-shortcuts.md)
28+
* [CSS style properties](reference/css-properties.md)
2929

guide/styling-with-css.md

Lines changed: 76 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Styling with CSS
22

3+
## Overview
4+
5+
One of the most powerful features in flutter-view is that it allows you to use CSS styles to flutter widgets, and to set any property of any flutter widget.
6+
7+
For example, you can start with a simple Container:
8+
9+
```yaml
10+
greeting(flutter-view)
11+
.example Hello world!
12+
```
13+
14+
This will generate a function that returns a Container with the class name "example", that in turns contains a Text widget with the text "Hello world".
15+
16+
Then you can style this Container by assigning Sass styles to the class:
17+
18+
```css
19+
.example
20+
width: 500
21+
height: 300
22+
color: red
23+
background-color: #333
24+
font-size: 20
25+
font-weight: bold
26+
```
27+
28+
Flutter-view will process your styles, attaching them to the classes. Properties such as width and height are directly assigned. Some properties are recognized as CSS properties, and generate more code, such as color and font-size. The result is a normal Dart function you can call in your normal Dart code to render the styled view. In this case, a grey box with red bold text saying "Hello world!".
29+
330
## Structuring your files for styling
431

532
**You can use CSS or Sass to set any property to any class or id in your Pug or HTML file.**
@@ -18,6 +45,13 @@ See the[ example projects](../get-started/examples.md) for more ideas for struct
1845

1946
**You can apply extra properties to html elements by adding them through style rules.**
2047

48+
To style anything in a flutter-view you:
49+
50+
1. add classes to the elements in your pug file,
51+
2. add style rules to these classes in the related sass file
52+
53+
To assign a class in pug, use the [Pug .classname syntax](https://pugjs.org/language/attributes.html#class-literal). Any div element becomes a Container widget.
54+
2155
For example, given the following Pug:
2256

2357
```c
@@ -50,48 +84,6 @@ Container(
5084
);
5185
```
5286

53-
## Setting expressions
54-
55-
**You can set an expression in CSS by wrapping the expression in quotes and starting it with a colon.**
56-
57-
It is recommended to keep Dart expressions in your Pug files. However, in some cases it can be practical to be able to set an expression as a value, for example if flutter-view does not have special support for it.
58-
59-
Say you want to achieve the following Dart:
60-
61-
```dart
62-
Table(
63-
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
64-
children: [ ... ]
65-
)
66-
```
67-
68-
Which you can achieve with the following Pug code:
69-
70-
```css
71-
table(:default-verticle-alignment='TableCellVerticalAlignment.middle')
72-
...children...
73-
```
74-
75-
Now let's move the `defaultVerticleAlignment` property into a Sass file:
76-
77-
{% tabs %}
78-
{% tab title="Sass" %}
79-
```css
80-
table
81-
default-verticle-alignment: ':TableCellVerticalAlignment.middle'
82-
```
83-
{% endtab %}
84-
85-
{% tab title="Pug" %}
86-
```css
87-
table
88-
...children...
89-
```
90-
{% endtab %}
91-
{% endtabs %}
92-
93-
Note the colon before `TableCellVerticleAlignment.middle`in the Sass file.
94-
9587
## Using shortcut properties in styles
9688

9789
**Flutter-view provides many shortcut properties, that let you style in a CSS-style manner.**
@@ -279,6 +271,48 @@ Card ArtistCard({ @required onBuyPressed, @required onListenPressed }) {
279271

280272
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.
281273

274+
## Setting expressions
275+
276+
**You can set an expression in CSS by wrapping the expression in quotes and starting it with a colon.**
277+
278+
It is recommended to keep Dart expressions in your Pug files. However, in some cases it can be practical to be able to set an expression as a CSS value, for example if flutter-view does not have special support for it.
279+
280+
Say you want to achieve the following Dart:
281+
282+
```dart
283+
Table(
284+
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
285+
children: [ ... ]
286+
)
287+
```
288+
289+
Which you can achieve with the following \(a bit contrived\) Pug code:
290+
291+
```css
292+
table(:default-verticle-alignment='TableCellVerticalAlignment.middle')
293+
...children...
294+
```
295+
296+
Now let's move the `defaultVerticleAlignment` property into a Sass file:
297+
298+
{% tabs %}
299+
{% tab title="Sass" %}
300+
```css
301+
table
302+
default-verticle-alignment: ':TableCellVerticalAlignment.middle'
303+
```
304+
{% endtab %}
305+
306+
{% tab title="Pug" %}
307+
```css
308+
table
309+
...children...
310+
```
311+
{% endtab %}
312+
{% endtabs %}
313+
314+
Note the colon before `TableCellVerticleAlignment.middle`in the Sass file.
315+
282316
## Using Flutter Themes in styles
283317

284318
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.

reference/css-properties.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: >-
55
Dart code.
66
---
77

8-
# CSS style shortcuts
8+
# CSS style properties
99

1010
## alignment
1111

reference/tag-shortcuts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >-
44
Dart code.
55
---
66

7-
# Pug tag shortcuts
7+
# Special pug tags
88

99
## function
1010

0 commit comments

Comments
 (0)