You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-1Lines changed: 5 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -57,11 +57,13 @@ Container Hello() {
57
57
{% endtab %}
58
58
{% endtabs %}
59
59
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
+
60
62
This generated function can be used like any other Dart code, and will return the code that gives the greeting.
61
63
62
64
## Adding Styling
63
65
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):
65
67
66
68
{% tabs %}
67
69
{% tab title="Pug" %}
@@ -118,6 +120,8 @@ Hello() {
118
120
{% endtab %}
119
121
{% endtabs %}
120
122
123
+
_Click the tabs to see the Pug code, the Sass styles we apply, and the code that flutter-view generates for you._
124
+
121
125
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.
122
126
123
127
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).
Copy file name to clipboardExpand all lines: guide/styling-with-css.md
+76-42Lines changed: 76 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,32 @@
1
1
# Styling with CSS
2
2
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
+
3
30
## Structuring your files for styling
4
31
5
32
**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
18
45
19
46
**You can apply extra properties to html elements by adding them through style rules.**
20
47
48
+
To style anything in aflutter-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 divelement becomes a Container widget.
54
+
21
55
For example, given the following Pug:
22
56
23
57
```c
@@ -50,48 +84,6 @@ Container(
50
84
);
51
85
```
52
86
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.
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.
281
273
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.
Note the colon before `TableCellVerticleAlignment.middle`in the Sass file.
315
+
282
316
## Using Flutter Themes in styles
283
317
284
318
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.
0 commit comments