forked from bluefireteam/photo_view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphoto_view.dart
89 lines (76 loc) · 2.02 KB
/
photo_view.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
library photo_view;
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'package:photo_view/photo_view_image_wrapper.dart';
import 'package:photo_view/photo_view_scale_type.dart';
import 'package:photo_view/photo_view_utils.dart';
class PhotoView extends StatefulWidget{
final ImageProvider imageProvider;
final Widget loadingChild;
PhotoView({
Key key,
@required this.imageProvider,
this.loadingChild
}) : super(key: key);
@override
State<StatefulWidget> createState() {
return new _PhotoViewState();
}
}
class _PhotoViewState extends State<PhotoView>{
PhotoViewScaleType _scaleType;
Future<ImageInfo> _getImage(){
Completer completer = new Completer<ImageInfo>();
ImageStream stream = widget.imageProvider.resolve(new ImageConfiguration());
stream.addListener((ImageInfo info, bool completed) {
completer.complete(info);
});
return completer.future;
}
void onDoubleTap () {
setState(() {
_scaleType = nextScaleType(_scaleType);
});
}
void onStartPanning () {
setState(() {
_scaleType = PhotoViewScaleType.zooming;
});
}
@override
void initState(){
super.initState();
_scaleType = PhotoViewScaleType.contained;
}
@override
Widget build(BuildContext context) {
return new FutureBuilder(
future: _getImage(),
builder: (BuildContext context, AsyncSnapshot<ImageInfo> info) {
if(info.hasData){
return new PhotoViewImageWrapper(
onDoubleTap: onDoubleTap,
onStartPanning: onStartPanning,
imageInfo: info.data,
scaleType: _scaleType,
);
} else {
return buildLoading();
}
}
);
}
Widget buildLoading() {
return widget.loadingChild != null
? widget.loadingChild
: new Center(
child: new Text(
"Loading",
style: new TextStyle(
color: Colors.white
),
)
);
}
}