|
@@ -3,6 +3,7 @@ import 'dart:typed_data';
|
3
|
3
|
|
4
|
4
|
import 'package:flutter/material.dart';
|
5
|
5
|
import 'package:photo/src/entity/options.dart';
|
|
6
|
+import 'package:photo/src/provider/asset_provider.dart';
|
6
|
7
|
import 'package:photo/src/provider/config_provider.dart';
|
7
|
8
|
import 'package:photo/src/provider/selected_provider.dart';
|
8
|
9
|
import 'package:photo/src/ui/page/photo_main_page.dart';
|
|
@@ -18,16 +19,23 @@ class PhotoPreviewPage extends StatefulWidget {
|
18
|
19
|
/// 这个参数是控制在内部点击check后是否实时修改provider状态
|
19
|
20
|
final bool changeProviderOnCheckChange;
|
20
|
21
|
|
|
22
|
+ /// 是否通过预览进来的
|
|
23
|
+ final bool isPreview;
|
|
24
|
+
|
21
|
25
|
/// 这里封装了结果
|
22
|
26
|
final PhotoPreviewResult result;
|
23
|
27
|
|
|
28
|
+ final AssetProvider assetProvider;
|
|
29
|
+
|
24
|
30
|
const PhotoPreviewPage({
|
25
|
31
|
Key key,
|
26
|
32
|
@required this.selectedProvider,
|
27
|
33
|
@required this.list,
|
28
|
34
|
@required this.changeProviderOnCheckChange,
|
29
|
35
|
@required this.result,
|
|
36
|
+ @required this.assetProvider,
|
30
|
37
|
this.initIndex = 0,
|
|
38
|
+ this.isPreview = false,
|
31
|
39
|
}) : super(key: key);
|
32
|
40
|
|
33
|
41
|
@override
|
|
@@ -35,7 +43,8 @@ class PhotoPreviewPage extends StatefulWidget {
|
35
|
43
|
}
|
36
|
44
|
|
37
|
45
|
class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
|
38
|
|
- ConfigProvider get config => ConfigProvider.of(context);
|
|
46
|
+ PhotoPickerProvider get config => PhotoPickerProvider.of(context);
|
|
47
|
+ AssetProvider get assetProvider => widget.assetProvider;
|
39
|
48
|
|
40
|
49
|
Options get options => config.options;
|
41
|
50
|
|
|
@@ -45,7 +54,12 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
|
45
|
54
|
|
46
|
55
|
SelectedProvider get selectedProvider => widget.selectedProvider;
|
47
|
56
|
|
48
|
|
- List<AssetEntity> get list => widget.list;
|
|
57
|
+ List<AssetEntity> get list {
|
|
58
|
+ if (!widget.isPreview) {
|
|
59
|
+ return assetProvider.data;
|
|
60
|
+ }
|
|
61
|
+ return widget.list;
|
|
62
|
+ }
|
49
|
63
|
|
50
|
64
|
StreamController<int> pageChangeController = StreamController.broadcast();
|
51
|
65
|
|
|
@@ -96,6 +110,13 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
|
96
|
110
|
|
97
|
111
|
@override
|
98
|
112
|
Widget build(BuildContext context) {
|
|
113
|
+ int totalCount = assetProvider.current.assetCount ?? 0;
|
|
114
|
+ if (!widget.isPreview) {
|
|
115
|
+ totalCount = assetProvider.current.assetCount;
|
|
116
|
+ } else {
|
|
117
|
+ totalCount = list.length;
|
|
118
|
+ }
|
|
119
|
+
|
99
|
120
|
var data = Theme.of(context);
|
100
|
121
|
var textStyle = TextStyle(
|
101
|
122
|
color: options.textColor,
|
|
@@ -114,33 +135,35 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
|
114
|
135
|
title: StreamBuilder(
|
115
|
136
|
stream: pageStream,
|
116
|
137
|
initialData: widget.initIndex,
|
117
|
|
- builder: (ctx, snap) => Text(
|
118
|
|
- "${snap.data + 1}/${widget.list.length}",
|
119
|
|
- style: TextStyle(
|
120
|
|
- color: options.textColor,
|
121
|
|
- ),
|
|
138
|
+ builder: (ctx, snap) {
|
|
139
|
+ return Text(
|
|
140
|
+ "${snap.data + 1}/$totalCount",
|
|
141
|
+ style: TextStyle(
|
|
142
|
+ color: options.textColor,
|
122
|
143
|
),
|
|
144
|
+ );
|
|
145
|
+ },
|
123
|
146
|
),
|
124
|
147
|
actions: <Widget>[
|
125
|
148
|
StreamBuilder(
|
126
|
149
|
stream: pageStream,
|
127
|
150
|
builder: (ctx, s) => FlatButton(
|
128
|
|
- splashColor: Colors.transparent,
|
129
|
|
- onPressed: selectedList.length == 0 ? null : sure,
|
130
|
|
- child: Text(
|
131
|
|
- config.provider.getSureText(options, selectedList.length),
|
132
|
|
- style: selectedList.length == 0
|
133
|
|
- ? textStyle.copyWith(color: options.disableColor)
|
134
|
|
- : textStyle,
|
135
|
|
- ),
|
136
|
|
- ),
|
|
151
|
+ splashColor: Colors.transparent,
|
|
152
|
+ onPressed: selectedList.length == 0 ? null : sure,
|
|
153
|
+ child: Text(
|
|
154
|
+ config.provider.getSureText(options, selectedList.length),
|
|
155
|
+ style: selectedList.length == 0
|
|
156
|
+ ? textStyle.copyWith(color: options.disableColor)
|
|
157
|
+ : textStyle,
|
|
158
|
+ ),
|
|
159
|
+ ),
|
137
|
160
|
),
|
138
|
161
|
],
|
139
|
162
|
),
|
140
|
163
|
body: PageView.builder(
|
141
|
164
|
controller: pageController,
|
142
|
165
|
itemBuilder: _buildItem,
|
143
|
|
- itemCount: list.length,
|
|
166
|
+ itemCount: totalCount,
|
144
|
167
|
onPageChanged: _onPageChanged,
|
145
|
168
|
),
|
146
|
169
|
bottomSheet: _buildThumb(),
|
|
@@ -244,6 +267,10 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
|
244
|
267
|
}
|
245
|
268
|
|
246
|
269
|
Widget _buildItem(BuildContext context, int index) {
|
|
270
|
+ if (!widget.isPreview && index >= list.length - 5) {
|
|
271
|
+ _loadMore();
|
|
272
|
+ }
|
|
273
|
+
|
247
|
274
|
var data = list[index];
|
248
|
275
|
return BigPhotoImage(
|
249
|
276
|
assetEntity: data,
|
|
@@ -251,6 +278,10 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
|
251
|
278
|
);
|
252
|
279
|
}
|
253
|
280
|
|
|
281
|
+ Future<void> _loadMore() async {
|
|
282
|
+ assetProvider.loadMore();
|
|
283
|
+ }
|
|
284
|
+
|
254
|
285
|
Widget _buildLoadingWidget(AssetEntity entity) {
|
255
|
286
|
return options.loadingDelegate
|
256
|
287
|
.buildBigImageLoading(context, entity, themeColor);
|
|
@@ -263,13 +294,13 @@ class _PhotoPreviewPageState extends State<PhotoPreviewPage> {
|
263
|
294
|
Widget _buildThumb() {
|
264
|
295
|
return StreamBuilder(
|
265
|
296
|
builder: (ctx, snapshot) => Container(
|
266
|
|
- height: 80.0,
|
267
|
|
- child: ListView.builder(
|
268
|
|
- itemBuilder: _buildThumbItem,
|
269
|
|
- itemCount: previewList.length,
|
270
|
|
- scrollDirection: Axis.horizontal,
|
271
|
|
- ),
|
272
|
|
- ),
|
|
297
|
+ height: 80.0,
|
|
298
|
+ child: ListView.builder(
|
|
299
|
+ itemBuilder: _buildThumbItem,
|
|
300
|
+ itemCount: previewList.length,
|
|
301
|
+ scrollDirection: Axis.horizontal,
|
|
302
|
+ ),
|
|
303
|
+ ),
|
273
|
304
|
stream: pageStream,
|
274
|
305
|
);
|
275
|
306
|
}
|