|
@@ -17,6 +17,7 @@ import 'package:photo/src/ui/dialog/change_gallery_dialog.dart';
|
17
|
17
|
import 'package:photo/src/ui/page/main/empty_widget.dart';
|
18
|
18
|
import 'package:photo/src/ui/page/photo_preview_page.dart';
|
19
|
19
|
import 'package:photo_manager/photo_manager.dart';
|
|
20
|
+import 'package:provider/provider.dart';
|
20
|
21
|
|
21
|
22
|
part './main/bottom_widget.dart';
|
22
|
23
|
part './main/image_item.dart';
|
|
@@ -39,11 +40,11 @@ class PhotoMainPage extends StatefulWidget {
|
39
|
40
|
|
40
|
41
|
class _PhotoMainPageState extends State<PhotoMainPage>
|
41
|
42
|
with SelectedProvider, GalleryListProvider {
|
|
43
|
+ PhotoProvider get config =>
|
|
44
|
+ Provider.of<PhotoProvider>(context, listen: false);
|
42
|
45
|
Options get options => widget.options;
|
43
|
|
-
|
44
|
|
- I18nProvider get i18nProvider => PhotoPickerProvider.of(context).provider;
|
45
|
|
- AssetProvider get assetProvider =>
|
46
|
|
- PhotoPickerProvider.of(context).assetProvider;
|
|
46
|
+ I18nProvider get i18nProvider => config.provider;
|
|
47
|
+ AssetProvider get assetProvider => config.assetProvider;
|
47
|
48
|
|
48
|
49
|
List<AssetEntity> get list => assetProvider.data;
|
49
|
50
|
|
|
@@ -81,7 +82,7 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
81
|
82
|
void didChangeDependencies() {
|
82
|
83
|
super.didChangeDependencies();
|
83
|
84
|
if (!_isInit) {
|
84
|
|
- final pickedList = PhotoPickerProvider.of(context).pickedAssetList ?? [];
|
|
85
|
+ final pickedList = config.pickedAssetList ?? [];
|
85
|
86
|
addPickedAsset(pickedList.toList());
|
86
|
87
|
_refreshList();
|
87
|
88
|
}
|
|
@@ -130,16 +131,16 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
130
|
131
|
Material(
|
131
|
132
|
color: options.theme.surfaceColor,
|
132
|
133
|
child: Container(
|
133
|
|
- height: MediaQuery.of(context).size.height * 0.5 - MediaQuery.of(context).padding.top,
|
|
134
|
+ height: MediaQuery.of(context).size.height * 0.5 -
|
|
135
|
+ MediaQuery.of(context).padding.top,
|
134
|
136
|
child: ChangeGalleryDialog(
|
135
|
|
- galleryList: galleryPathList,
|
136
|
|
- i18n: i18nProvider,
|
137
|
|
- options: options,
|
138
|
|
- current: assetProvider.current,
|
139
|
|
- onGalleryChange: (AssetPathEntity result) {
|
140
|
|
- _onGalleryChange?.call(result);
|
141
|
|
- }
|
142
|
|
- ),
|
|
137
|
+ galleryList: galleryPathList,
|
|
138
|
+ i18n: i18nProvider,
|
|
139
|
+ options: options,
|
|
140
|
+ current: assetProvider.current,
|
|
141
|
+ onGalleryChange: (AssetPathEntity result) {
|
|
142
|
+ _onGalleryChange?.call(result);
|
|
143
|
+ }),
|
143
|
144
|
),
|
144
|
145
|
),
|
145
|
146
|
],
|
|
@@ -169,41 +170,47 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
169
|
170
|
splashColor: Colors.transparent,
|
170
|
171
|
highlightColor: Colors.transparent,
|
171
|
172
|
child: Container(
|
172
|
|
- alignment: Alignment.center,
|
173
|
|
- height: 44.0,
|
174
|
|
- padding: EdgeInsets.zero.copyWith(right: kToolbarHeight),
|
175
|
|
- child: Row(
|
176
|
|
- mainAxisAlignment: MainAxisAlignment.center,
|
177
|
|
- children: [
|
178
|
|
- Text(currentGalleryName, style: options.theme.textStyle.apply(
|
179
|
|
- fontSizeDelta: 2.0,
|
180
|
|
- fontWeightDelta: 1,
|
181
|
|
- ),),
|
182
|
|
- Container(
|
183
|
|
- width: 18,
|
184
|
|
- height: 18,
|
185
|
|
- margin: EdgeInsets.only(left: 8),
|
186
|
|
- decoration: ShapeDecoration(shape: CircleBorder(
|
187
|
|
- side: BorderSide(
|
188
|
|
- color: options.theme.onSurfaceColor,
|
189
|
|
- width: 1.5
|
|
173
|
+ alignment: Alignment.center,
|
|
174
|
+ height: 44.0,
|
|
175
|
+ padding: EdgeInsets.zero.copyWith(right: kToolbarHeight),
|
|
176
|
+ child: Row(
|
|
177
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
178
|
+ children: [
|
|
179
|
+ Text(
|
|
180
|
+ currentGalleryName,
|
|
181
|
+ style: options.theme.textStyle.apply(
|
|
182
|
+ fontSizeDelta: 2.0,
|
|
183
|
+ fontWeightDelta: 1,
|
190
|
184
|
),
|
191
|
|
- )),
|
192
|
|
- child: AnimatedSwitcher(
|
193
|
|
- transitionBuilder: (child, animation){
|
194
|
|
- final Tween<double> tween = overlayEntry != null ? Tween(begin: -0.25, end: 0.25) : Tween(begin: 0.25, end: 0.75);
|
195
|
|
- //var tween = Tween(begin: -0.5, end: 0.0);
|
196
|
|
- return RotationTransition(child: child, turns: tween.animate(animation));
|
197
|
|
- },
|
198
|
|
- duration: Duration(milliseconds: 200),
|
199
|
|
- reverseDuration: Duration(milliseconds: 0),
|
200
|
|
- child: Icon(Icons.chevron_left, key: ValueKey(overlayEntry == null ? 0 : 1), size: 14, color: options.theme.onSurfaceColor),
|
201
|
185
|
),
|
202
|
|
- ),
|
203
|
|
- ],
|
204
|
|
- )
|
205
|
|
-
|
206
|
|
- ),
|
|
186
|
+ Container(
|
|
187
|
+ width: 18,
|
|
188
|
+ height: 18,
|
|
189
|
+ margin: EdgeInsets.only(left: 8),
|
|
190
|
+ decoration: ShapeDecoration(
|
|
191
|
+ shape: CircleBorder(
|
|
192
|
+ side: BorderSide(
|
|
193
|
+ color: options.theme.onSurfaceColor, width: 1.5),
|
|
194
|
+ )),
|
|
195
|
+ child: AnimatedSwitcher(
|
|
196
|
+ transitionBuilder: (child, animation) {
|
|
197
|
+ final Tween<double> tween = overlayEntry != null
|
|
198
|
+ ? Tween(begin: -0.25, end: 0.25)
|
|
199
|
+ : Tween(begin: 0.25, end: 0.75);
|
|
200
|
+ //var tween = Tween(begin: -0.5, end: 0.0);
|
|
201
|
+ return RotationTransition(
|
|
202
|
+ child: child, turns: tween.animate(animation));
|
|
203
|
+ },
|
|
204
|
+ duration: Duration(milliseconds: 200),
|
|
205
|
+ reverseDuration: Duration(milliseconds: 0),
|
|
206
|
+ child: Icon(Icons.chevron_left,
|
|
207
|
+ key: ValueKey(overlayEntry == null ? 0 : 1),
|
|
208
|
+ size: 14,
|
|
209
|
+ color: options.theme.onSurfaceColor),
|
|
210
|
+ ),
|
|
211
|
+ ),
|
|
212
|
+ ],
|
|
213
|
+ )),
|
207
|
214
|
),
|
208
|
215
|
),
|
209
|
216
|
body: _buildBody(),
|
|
@@ -248,7 +255,8 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
248
|
255
|
SnackBar(
|
249
|
256
|
content: Text(
|
250
|
257
|
msg,
|
251
|
|
- style: options.theme.textStyle.copyWith(color: options.theme.onPrimaryColor),
|
|
258
|
+ style: options.theme.textStyle
|
|
259
|
+ .copyWith(color: options.theme.onPrimaryColor),
|
252
|
260
|
),
|
253
|
261
|
duration: Duration(milliseconds: 1500),
|
254
|
262
|
backgroundColor: options.theme.primaryColor.withOpacity(0.7),
|
|
@@ -326,17 +334,19 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
326
|
334
|
return Container(
|
327
|
335
|
color: options.theme.backgroundColor,
|
328
|
336
|
padding: EdgeInsets.all(5),
|
329
|
|
- child: assetProvider.count == 0 ? DefaultEmptyDelegate().buildEmpty(context, options) : GridView.builder(
|
330
|
|
- controller: scrollController,
|
331
|
|
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
332
|
|
- crossAxisCount: options.rowCount,
|
333
|
|
- childAspectRatio: options.itemRadio,
|
334
|
|
- crossAxisSpacing: options.padding,
|
335
|
|
- mainAxisSpacing: options.padding,
|
336
|
|
- ),
|
337
|
|
- itemBuilder: _buildItem,
|
338
|
|
- itemCount: count,
|
339
|
|
- ),
|
|
337
|
+ child: assetProvider.count == 0
|
|
338
|
+ ? DefaultEmptyDelegate().buildEmpty(context, options)
|
|
339
|
+ : GridView.builder(
|
|
340
|
+ controller: scrollController,
|
|
341
|
+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
342
|
+ crossAxisCount: options.rowCount,
|
|
343
|
+ childAspectRatio: options.itemRadio,
|
|
344
|
+ crossAxisSpacing: options.padding,
|
|
345
|
+ mainAxisSpacing: options.padding,
|
|
346
|
+ ),
|
|
347
|
+ itemBuilder: _buildItem,
|
|
348
|
+ itemCount: count,
|
|
349
|
+ ),
|
340
|
350
|
);
|
341
|
351
|
}
|
342
|
352
|
|
|
@@ -401,7 +411,9 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
401
|
411
|
Widget _buildText(AssetEntity entity) {
|
402
|
412
|
var isSelected = containsEntity(entity);
|
403
|
413
|
Widget child;
|
404
|
|
- BoxDecoration decoration = BoxDecoration(borderRadius: BorderRadius.circular(1.0),);
|
|
414
|
+ BoxDecoration decoration = BoxDecoration(
|
|
415
|
+ borderRadius: BorderRadius.circular(1.0),
|
|
416
|
+ );
|
405
|
417
|
if (isSelected) {
|
406
|
418
|
child = Text(
|
407
|
419
|
(indexOfSelected(entity) + 1).toString(),
|
|
@@ -413,9 +425,11 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
413
|
425
|
);
|
414
|
426
|
decoration = decoration.copyWith(color: options.theme.primaryColor);
|
415
|
427
|
} else {
|
416
|
|
- decoration = decoration.copyWith(border: Border.all(
|
417
|
|
- color: options.theme.onPrimaryColor.withAlpha(200),
|
418
|
|
- ),);
|
|
428
|
+ decoration = decoration.copyWith(
|
|
429
|
+ border: Border.all(
|
|
430
|
+ color: options.theme.onPrimaryColor.withAlpha(200),
|
|
431
|
+ ),
|
|
432
|
+ );
|
419
|
433
|
}
|
420
|
434
|
return Padding(
|
421
|
435
|
padding: const EdgeInsets.all(8.0),
|
|
@@ -452,9 +466,8 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
452
|
466
|
Navigator.of(context).push(
|
453
|
467
|
MaterialPageRoute(
|
454
|
468
|
builder: (ctx) {
|
455
|
|
- return PhotoPickerProvider(
|
456
|
|
- provider: PhotoPickerProvider.of(context).provider,
|
457
|
|
- options: options,
|
|
469
|
+ return ChangeNotifierProvider.value(
|
|
470
|
+ value: config,
|
458
|
471
|
child: PhotoPreviewPage(
|
459
|
472
|
selectedProvider: this,
|
460
|
473
|
list: List.of(list),
|
|
@@ -482,9 +495,8 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
482
|
495
|
isPushed = true;
|
483
|
496
|
var v = await Navigator.of(context).push(
|
484
|
497
|
MaterialPageRoute(
|
485
|
|
- builder: (ctx) => PhotoPickerProvider(
|
486
|
|
- provider: PhotoPickerProvider.of(context).provider,
|
487
|
|
- options: options,
|
|
498
|
+ builder: (ctx) => ChangeNotifierProvider.value(
|
|
499
|
+ value: config,
|
488
|
500
|
child: PhotoPreviewPage(
|
489
|
501
|
selectedProvider: this,
|
490
|
502
|
list: List.of(selectedList),
|