X Tutup
Skip to content

Commit 8342670

Browse files
committed
增加图片预览
1 parent 9c523de commit 8342670

File tree

7 files changed

+74
-11
lines changed

7 files changed

+74
-11
lines changed

lib/common/style/GSYStyle.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ class GSYICons {
340340
static const String FONT_FAMILY = 'wxcIconFont';
341341

342342
static const String DEFAULT_USER_ICON = 'static/images/logo.png';
343+
static const String DEFAULT_IMAGE = 'static/images/default_img.png';
343344
static const String DEFAULT_REMOTE_PIC = 'https://raw.githubusercontent.com/CarGuo/GSYGithubAppFlutter/master/static/images/logo.png';
344345

345346
static const IconData HOME = const IconData(0xe624, fontFamily: GSYICons.FONT_FAMILY);

lib/common/utils/NavigatorUtils.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:gsy_github_app_flutter/page/IssueDetailPage.dart';
1111
import 'package:gsy_github_app_flutter/page/LoginPage.dart';
1212
import 'package:gsy_github_app_flutter/page/NotifyPage.dart';
1313
import 'package:gsy_github_app_flutter/page/PersonPage.dart';
14+
import 'package:gsy_github_app_flutter/page/PhotoViewPage.dart';
1415
import 'package:gsy_github_app_flutter/page/PushDetailPage.dart';
1516
import 'package:gsy_github_app_flutter/page/ReleasePage.dart';
1617
import 'package:gsy_github_app_flutter/page/RepositoryDetailPage.dart';
@@ -182,4 +183,9 @@ class NavigatorUtils {
182183
);
183184
}
184185
}
186+
187+
///图片预览
188+
static gotoPhotoViewPage(BuildContext context, String url) {
189+
Navigator.push(context, new MaterialPageRoute(builder: (context) => new PhotoViewPage(url)));
190+
}
185191
}

lib/page/PhotoViewPage.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_spinkit/flutter_spinkit.dart';
3+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
4+
import 'package:photo_view/photo_view.dart';
5+
6+
/**
7+
* 图片预览
8+
* Created by guoshuyu
9+
* Date: 2018-08-09
10+
*/
11+
12+
class PhotoViewPage extends StatelessWidget {
13+
final String url;
14+
15+
PhotoViewPage(this.url);
16+
17+
@override
18+
Widget build(BuildContext context) {
19+
return new Scaffold(
20+
appBar: new AppBar(),
21+
body: new Container(
22+
child: new PhotoView(
23+
imageProvider: new NetworkImage(url ?? GSYICons.DEFAULT_REMOTE_PIC),
24+
loadingChild: Container(
25+
child: new Stack(
26+
children: <Widget>[
27+
new Center(child: new Image.asset(GSYICons.DEFAULT_IMAGE)),
28+
new Center(child: new SpinKitDoubleBounce(color: Color(GSYColors.primaryValue))),
29+
],
30+
),
31+
),
32+
),
33+
)
34+
);
35+
36+
}
37+
}

lib/widget/UserHeader.dart

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class UserHeaderItem extends StatelessWidget {
8383
padding: EdgeInsets.only(left: 10.0, right: 10.0),
8484
width: width,
8585
height: height,
86+
8687
///svg chart
8788
child: new SvgPicture.network(
8889
CommonUtils.getUserChartAddress(userInfo.login),
@@ -93,7 +94,7 @@ class UserHeaderItem extends StatelessWidget {
9394
height: height,
9495
width: width,
9596
child: Center(
96-
child: const SpinKitRipple (color: Color(GSYColors.primaryValue)),
97+
child: const SpinKitRipple(color: Color(GSYColors.primaryValue)),
9798
),
9899
),
99100
),
@@ -126,16 +127,25 @@ class UserHeaderItem extends StatelessWidget {
126127
crossAxisAlignment: CrossAxisAlignment.start,
127128
children: <Widget>[
128129
///用户头像
129-
new ClipOval(
130-
child: new FadeInImage.assetNetwork(
131-
placeholder: GSYICons.DEFAULT_USER_ICON,
132-
//预览图
133-
fit: BoxFit.fitWidth,
134-
image: userInfo.avatar_url ?? GSYICons.DEFAULT_REMOTE_PIC,
135-
width: 80.0,
136-
height: 80.0,
137-
),
138-
),
130+
new RawMaterialButton(
131+
onPressed: () {
132+
if (userInfo.avatar_url != null) {
133+
NavigatorUtils.gotoPhotoViewPage(context, userInfo.avatar_url);
134+
}
135+
},
136+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
137+
padding: const EdgeInsets.all(0.0),
138+
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
139+
child: new ClipOval(
140+
child: new FadeInImage.assetNetwork(
141+
placeholder: GSYICons.DEFAULT_USER_ICON,
142+
//预览图
143+
fit: BoxFit.fitWidth,
144+
image: userInfo.avatar_url ?? GSYICons.DEFAULT_REMOTE_PIC,
145+
width: 80.0,
146+
height: 80.0,
147+
),
148+
)),
139149
new Padding(padding: EdgeInsets.all(10.0)),
140150
new Expanded(
141151
child: new Column(

pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ packages:
377377
url: "https://pub.flutter-io.cn"
378378
source: hosted
379379
version: "1.7.7"
380+
photo_view:
381+
dependency: "direct main"
382+
description:
383+
name: photo_view
384+
url: "https://pub.flutter-io.cn"
385+
source: hosted
386+
version: "0.0.4"
380387
plugin:
381388
dependency: transitive
382389
description:

pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies:
2525
pub_semver: ^1.4.2
2626
flutter_statusbar: ^0.0.1
2727
flutter_svg: ^0.5.4
28+
photo_view: ^0.0.3
2829

2930
dev_dependencies:
3031
build_runner: ^0.7.6
@@ -78,6 +79,7 @@ flutter:
7879
assets:
7980
- static/images/logo.png
8081
- static/images/welcome.png
82+
- static/images/default_img.png
8183

8284
fonts:
8385
- family: wxcIconFont

static/images/default_img.png

18.4 KB
Loading

0 commit comments

Comments
 (0)
X Tutup