Skip to content

Commit d776542

Browse files
committed
AspectRatio
1 parent b0ee630 commit d776542

File tree

6 files changed

+91
-1
lines changed

6 files changed

+91
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## **AspectRatio**
2+
3+
>
4+
将子控件调整为特定宽高比的控件
5+
* AspectRatio 首先会尝试布局约束的最大宽度,widget的高度是通过给定的宽度和宽高比率来决定的
6+
* 对于需要缩放调整位置的,一般是对图片的处理
7+
8+
### 构造方法
9+
``` dart
10+
AspectRatio({
11+
Key key,
12+
@required this.aspectRatio,
13+
Widget child
14+
})
15+
```
16+
17+
### 属性介绍
18+
* aspectRatio: 宽高比,如1.5,宽度是高度的1.5倍
19+
* child: AspectRatio中的内容widget
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Index extends StatefulWidget {
4+
@override
5+
_IndexState createState() => _IndexState();
6+
}
7+
8+
class _IndexState extends State<Index> {
9+
var aspectRatio = 1.5;
10+
@override
11+
Widget build(BuildContext context) {
12+
return Scaffold(
13+
appBar: AppBar(title: Text('AspectRatio'),),
14+
body: ListView(
15+
children: <Widget>[
16+
Container(
17+
// margin: const EdgeInsets.only(top: 10.0),
18+
width: double.infinity,
19+
child: AspectRatio(
20+
aspectRatio: aspectRatio,
21+
child: Image.network(
22+
'http://pic1.win4000.com/wallpaper/2019-01-31/5c52bf7fdc959_270_185.jpg',
23+
fit: BoxFit.cover,
24+
),
25+
)
26+
),
27+
FlatButton(
28+
child: Text('宽度沾满,aspectRatio: $aspectRatio', style: TextStyle(fontSize: 16.0),),
29+
onPressed: (){
30+
setState(() {
31+
aspectRatio == 1.5 ? aspectRatio = 2.0 : aspectRatio = 1.5;
32+
});
33+
},
34+
)
35+
],
36+
)
37+
);
38+
}
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+
import 'demo.dart' as Demo;
4+
5+
class Index extends StatefulWidget {
6+
static String title = 'AspectRatio';
7+
static String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/AspectRatio-class.html';
8+
static String mdUrl = 'docs/widget/regular/aspectratio/index.md';
9+
@override
10+
_IndexState createState() => _IndexState();
11+
}
12+
13+
class _IndexState extends State<Index> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return WidgetComp.Index(
17+
title: Index.title,
18+
originCodeUrl: Index.originCodeUrl,
19+
mdUrl: Index.mdUrl,
20+
demoChild: <Widget>[
21+
Demo.Index()
22+
],
23+
);
24+
}
25+
}

lib/widget/regular/fittedbox/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'demo.dart' as Demo;
44

55
class Index extends StatefulWidget {
66
static String title = 'FittedBox';
7-
static String originCodeUrl = '';
7+
static String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/FittedBox-class.html';
88
static String mdUrl = 'docs/widget/regular/fittedbox/index.md';
99
@override
1010
_IndexState createState() => _IndexState();

lib/widget/regular/index.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'padding/index.dart' as Padding;
66
import 'align/index.dart' as Align;
77
import 'center/index.dart' as Center;
88
import 'fittedbox/index.dart' as FittedBox;
9+
import 'aspectratio/index.dart' as AspectRatio;
910

1011
const nameSpaces = '/regular_';
1112

@@ -44,6 +45,11 @@ List widgets = [
4445
widget: FittedBox.Index(),
4546
code: 60231, // format_indent_decrease
4647
title: FittedBox.Index.title
48+
),
49+
ItemInfo(
50+
widget: AspectRatio.Index(),
51+
code: 58688, // local_bar
52+
title: AspectRatio.Index.title
4753
)
4854
];
4955

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ flutter:
6363
- docs/widget/regular/align/
6464
- docs/widget/regular/center/
6565
- docs/widget/regular/fittedbox/
66+
- docs/widget/regular/aspectratio/
6667
# An image asset can refer to one or more resolution-specific "variants", see
6768
# https://flutter.io/assets-and-images/#resolution-aware.
6869

0 commit comments

Comments
 (0)