17
17
*/
18
18
19
19
import 'package:flutter/material.dart' ;
20
- import 'package:flutter/widgets.dart' ;
21
20
import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
22
21
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart' ;
23
22
import 'package:intl/intl.dart' ;
@@ -36,76 +35,79 @@ class Gallery extends StatelessWidget {
36
35
37
36
return Padding (
38
37
padding: const EdgeInsets .all (5 ),
39
- child: MasonryGridView .count (
40
- crossAxisCount: 2 ,
41
- mainAxisSpacing: 5 ,
42
- crossAxisSpacing: 5 ,
43
- itemCount: provider.images.length,
44
- itemBuilder: (context, index) {
45
- final currentImage = provider.images[index];
38
+ child: RefreshIndicator (
39
+ onRefresh: () => provider.fetchAndSetGallery (),
40
+ child: MasonryGridView .count (
41
+ crossAxisCount: 2 ,
42
+ mainAxisSpacing: 5 ,
43
+ crossAxisSpacing: 5 ,
44
+ itemCount: provider.images.length,
45
+ itemBuilder: (context, index) {
46
+ final currentImage = provider.images[index];
46
47
47
- return GestureDetector (
48
- onTap: () {
49
- showModalBottomSheet (
50
- builder: (context) => Material (
51
- child: Container (
52
- key: Key ('image-${currentImage .id }-detail' ),
53
- padding: const EdgeInsets .all (10 ),
54
- color: Colors .white,
55
- child: Column (
56
- children: [
57
- Text (
58
- DateFormat .yMd (Localizations .localeOf (context).languageCode)
59
- .format (currentImage.date),
60
- style: Theme .of (context).textTheme.headline5,
61
- ),
62
- Expanded (
63
- child: Image .network (currentImage.url! ),
64
- ),
65
- Padding (
66
- padding: const EdgeInsets .symmetric (vertical: 8 ),
67
- child: Text (currentImage.description),
68
- ),
69
- Row (
70
- mainAxisAlignment: MainAxisAlignment .center,
71
- children: [
72
- IconButton (
73
- icon: const Icon (Icons .delete),
74
- onPressed: () {
75
- Provider .of <GalleryProvider >(context, listen: false )
76
- .deleteImage (currentImage);
77
- Navigator .of (context).pop ();
78
- }),
79
- IconButton (
80
- icon: const Icon (Icons .edit),
81
- onPressed: () {
82
- Navigator .pushNamed (
83
- context,
84
- FormScreen .routeName,
85
- arguments: FormScreenArguments (
86
- AppLocalizations .of (context).edit,
87
- ImageForm (currentImage),
88
- hasListView: true ,
89
- ),
90
- );
91
- }),
92
- ],
93
- )
94
- ],
48
+ return GestureDetector (
49
+ onTap: () {
50
+ showModalBottomSheet (
51
+ builder: (context) => Material (
52
+ child: Container (
53
+ key: Key ('image-${currentImage .id }-detail' ),
54
+ padding: const EdgeInsets .all (10 ),
55
+ color: Colors .white,
56
+ child: Column (
57
+ children: [
58
+ Text (
59
+ DateFormat .yMd (Localizations .localeOf (context).languageCode)
60
+ .format (currentImage.date),
61
+ style: Theme .of (context).textTheme.headline5,
62
+ ),
63
+ Expanded (
64
+ child: Image .network (currentImage.url! ),
65
+ ),
66
+ Padding (
67
+ padding: const EdgeInsets .symmetric (vertical: 8 ),
68
+ child: Text (currentImage.description),
69
+ ),
70
+ Row (
71
+ mainAxisAlignment: MainAxisAlignment .center,
72
+ children: [
73
+ IconButton (
74
+ icon: const Icon (Icons .delete),
75
+ onPressed: () {
76
+ Provider .of <GalleryProvider >(context, listen: false )
77
+ .deleteImage (currentImage);
78
+ Navigator .of (context).pop ();
79
+ }),
80
+ IconButton (
81
+ icon: const Icon (Icons .edit),
82
+ onPressed: () {
83
+ Navigator .pushNamed (
84
+ context,
85
+ FormScreen .routeName,
86
+ arguments: FormScreenArguments (
87
+ AppLocalizations .of (context).edit,
88
+ ImageForm (currentImage),
89
+ hasListView: true ,
90
+ ),
91
+ );
92
+ }),
93
+ ],
94
+ )
95
+ ],
96
+ ),
95
97
),
96
98
),
97
- ) ,
98
- context : context,
99
- );
100
- },
101
- child : FadeInImage (
102
- key : Key ( 'image-${ currentImage . id } ' ),
103
- placeholder : const AssetImage ( 'assets/images/placeholder.png' ),
104
- image : NetworkImage (currentImage.url ! ) ,
105
- fit : BoxFit .cover ,
106
- ),
107
- );
108
- } ),
99
+ context : context ,
100
+ );
101
+ },
102
+ child : FadeInImage (
103
+ key : Key ( 'image-${ currentImage . id }' ),
104
+ placeholder : const AssetImage ( 'assets/images/placeholder.png ' ),
105
+ image : NetworkImage (currentImage.url ! ),
106
+ fit : BoxFit .cover ,
107
+ ) ,
108
+ );
109
+ }),
110
+ ),
109
111
);
110
112
}
111
113
}
0 commit comments