-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathimage_size_page.dart
110 lines (96 loc) · 3.1 KB
/
image_size_page.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_wanandroid/res/styles.dart';
class ImageSizePage extends StatefulWidget {
final String title;
ImageSizePage(this.title);
@override
State<StatefulWidget> createState() {
return new _ImageSizePageState();
}
}
class _ImageSizePageState extends State<ImageSizePage> {
String cacheImgInfo1 = "[CachedNetworkImage] loading...";
String netImgInfo1 = "[网络图片1] loading...";
String localImgInfo1 = "[本地图片 ali_connors] loading...";
String netImgInfoE = "[网络图片E] loading...";
String netUrl1 =
"https://upload-images.jianshu.io/upload_images/13222938-74a4dc4115d76790.png";
String netUrl2 =
"https://upload-images.jianshu.io/upload_images/13222938-74a4dc4115d76790.png";
String netUrlE = "https://xxx.png";
String localImgUrl = "assets/images/3.0x/ali_connors.png";
@override
void initState() {
super.initState();
_loadCachedNetworkImage();
_loadNetUrl1();
_loadLocalUrl1();
_initAsync2();
}
void _loadCachedNetworkImage() async {
Image image = new Image(image: new CachedNetworkImageProvider(netUrl2));
Rect rect = await WidgetUtil.getImageWH(image: image);
cacheImgInfo1 =
"[CachedNetworkImage] width: ${rect.width}, height: ${rect.height}";
setState(() {});
// Image imageAsset = new Image.asset("");
// Image imageFile = new Image.file(File("path"));
// Image imageNetwork = new Image.network("url");
// Image imageMemory = new Image.memory(null);
}
void _loadNetUrl1() async {
Rect rect = await WidgetUtil.getImageWH(url: netUrl1);
netImgInfo1 = "[网络图片1] width: ${rect.width}, height: ${rect.height}";
setState(() {});
}
void _loadLocalUrl1() async {
Rect locImg1 = await WidgetUtil.getImageWH(localUrl: localImgUrl);
localImgInfo1 =
"[本地图片 ali_connors] width: ${locImg1.width}, height: ${locImg1.height}";
setState(() {});
}
void _initAsync2() {
WidgetUtil.getImageWHE(url: netUrlE).then((Rect rect) {
netImgInfoE = "[网络图片2] width: ${rect.width}, height: ${rect.height}";
setState(() {});
}).catchError((error) {
netImgInfoE = "[网络图片2] error" + error.toString();
setState(() {});
});
}
Widget _buildItem(String info, {double height = 50}) {
return new Container(
alignment: Alignment.center,
height: height,
child: new Text(
"$info",
style: TextStyles.listContent,
),
decoration: Decorations.bottom,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
centerTitle: true,
),
body: new ListView(
children: <Widget>[
_buildItem(cacheImgInfo1),
_buildItem(netImgInfo1),
_buildItem(localImgInfo1),
_buildItem(netImgInfoE, height: 100),
],
),
);
}
@override
void dispose() {
super.dispose();
}
}