-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlexAbout.dart
81 lines (78 loc) · 2.67 KB
/
FlexAbout.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import 'package:flutter/material.dart';
import 'package:flutter_starter_notes/component/CommonTitle.dart';
class FlexAbout extends StatelessWidget {
FlexAbout({Key key, this.title});
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
CommonTitle('Flex 介绍'),
Container(
padding: EdgeInsets.all(16),
child: Text(
"Flex可以沿着水平或垂直方向排列子widget,如果你知道主轴方向,使用Row或Column会方便一些,因为Row和Column都继承自Flex,参数基本相同,所以能使用Flex的地方一定可以使用Row或Column。"),
),
CommonTitle('Expanded 介绍以及 flex 弹性系数'),
Container(
padding: EdgeInsets.all(16),
child: Text(
"flex为弹性系数,如果为0或null,则child是没有弹性的,即不会被扩伸占用的空间。如果大于0,所有的Expanded按照其flex的比例来分割主轴的全部空闲空间。"),
),
CommonTitle('Flex: horizontal, flex: 1:2'),
//Flex的两个子widget按1:2来占据水平空间
Flex(
direction: Axis.horizontal,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
height: 30.0,
color: Colors.red,
),
),
Expanded(
flex: 2,
child: Container(
height: 30.0,
color: Colors.green,
),
),
],
),
CommonTitle('Flex: vertical, flex: 2:1:1'),
SizedBox(
height: 100,
child: Flex(
direction: Axis.vertical,
children: <Widget>[
Expanded(
flex: 2,
child: Container(
color: Colors.red,
),
),
Spacer(
flex: 1,
),
Expanded(
flex: 1,
child: Container(
height: 100, // 因为设置了 flex ,这里的高度将会不起作用
color: Colors.green,
),
),
],
),
),
],
),
),
);
}
}