@@ -63,22 +63,12 @@ class _LandingPageState extends ConsumerState<LandingPage> {
63
63
},
64
64
);
65
65
66
- ImageProvider _getProjectPreviewImageProvider (Uint8List img) => Image .memory (
67
- img,
68
- fit: BoxFit .cover,
69
- ).image;
70
-
71
- BoxDecoration _getPreviewForLatestModifiedProject (Project project) {
72
- Uint8List ? img = _getProjectPreview (project.imagePreviewPath);
73
- if (img != null ) {
74
- return BoxDecoration (
75
- color: Colors .white54,
76
- image: DecorationImage (
77
- image: _getProjectPreviewImageProvider (img),
78
- ),
79
- );
66
+ Widget _getPreviewForLatestModifiedProject (Project ? project) {
67
+ Uint8List ? img;
68
+ if (project != null ) {
69
+ img = _getProjectPreview (project.imagePreviewPath);
80
70
}
81
- return const BoxDecoration ( color: Colors .white54);
71
+ return _ImagePreview (img : img, color: Colors .white54);
82
72
}
83
73
84
74
void _clearCanvas () {
@@ -88,6 +78,11 @@ class _LandingPageState extends ConsumerState<LandingPage> {
88
78
ref.read (WorkspaceState .provider.notifier).updateLastSavedCommandCount ();
89
79
}
90
80
81
+ void _openProject (Project project, IOHandler ioHandler) async {
82
+ bool loaded = await _loadProject (ioHandler, project);
83
+ if (loaded) _navigateToPocketPaint ();
84
+ }
85
+
91
86
@override
92
87
Widget build (BuildContext context) {
93
88
final db = ref.watch (ProjectDatabase .provider);
@@ -113,13 +108,8 @@ class _LandingPageState extends ConsumerState<LandingPage> {
113
108
builder: (BuildContext context, AsyncSnapshot <List <Project >> snapshot) {
114
109
if (snapshot.connectionState == ConnectionState .done &&
115
110
snapshot.hasData) {
116
- BoxDecoration bigImg;
117
111
if (snapshot.data! .isNotEmpty) {
118
112
latestModifiedProject = snapshot.data! [0 ];
119
- bigImg =
120
- _getPreviewForLatestModifiedProject (latestModifiedProject! );
121
- } else {
122
- bigImg = const BoxDecoration (color: Colors .white54);
123
113
}
124
114
return Column (
125
115
children: [
@@ -131,15 +121,11 @@ class _LandingPageState extends ConsumerState<LandingPage> {
131
121
child: InkWell (
132
122
onTap: () async {
133
123
if (latestModifiedProject != null ) {
134
- bool loaded = await _loadProject (
135
- ioHandler,
136
- latestModifiedProject! ,
137
- );
138
- if (loaded) _navigateToPocketPaint ();
124
+ _openProject (latestModifiedProject! , ioHandler);
139
125
}
140
126
},
141
- child: Container (
142
- decoration : bigImg ,
127
+ child: _getPreviewForLatestModifiedProject (
128
+ latestModifiedProject ,
143
129
),
144
130
),
145
131
),
@@ -149,11 +135,7 @@ class _LandingPageState extends ConsumerState<LandingPage> {
149
135
iconSize: 264 ,
150
136
onPressed: () async {
151
137
if (latestModifiedProject != null ) {
152
- bool loaded = await _loadProject (
153
- ioHandler,
154
- latestModifiedProject! ,
155
- );
156
- if (loaded) _navigateToPocketPaint ();
138
+ _openProject (latestModifiedProject! , ioHandler);
157
139
}
158
140
},
159
141
icon: SvgPicture .asset (
@@ -198,27 +180,15 @@ class _LandingPageState extends ConsumerState<LandingPage> {
198
180
itemBuilder: (context, position) {
199
181
if (position != 0 ) {
200
182
Project project = snapshot.data! [position];
201
- BoxDecoration imagePreview;
202
183
Uint8List ? img =
203
184
_getProjectPreview (project.imagePreviewPath);
204
- if (img != null ) {
205
- imagePreview = BoxDecoration (
206
- color: Colors .white,
207
- image: DecorationImage (
208
- image: _getProjectPreviewImageProvider (img),
209
- ),
210
- );
211
- } else {
212
- imagePreview =
213
- const BoxDecoration (color: Colors .white);
214
- }
215
-
216
185
return Card (
217
186
// margin: const EdgeInsets.all(5),
218
187
child: ListTile (
219
- leading: Container (
188
+ leading: _ImagePreview (
189
+ img: img,
220
190
width: 80 ,
221
- decoration : imagePreview ,
191
+ color : Colors .white ,
222
192
),
223
193
dense: false ,
224
194
title: Text (
@@ -234,11 +204,7 @@ class _LandingPageState extends ConsumerState<LandingPage> {
234
204
project: project,
235
205
),
236
206
enabled: true ,
237
- onTap: () async {
238
- bool loaded =
239
- await _loadProject (ioHandler, project);
240
- if (loaded) _navigateToPocketPaint ();
241
- },
207
+ onTap: () async => _openProject (project, ioHandler),
242
208
),
243
209
);
244
210
}
@@ -263,11 +229,9 @@ class _LandingPageState extends ConsumerState<LandingPage> {
263
229
floatingActionButton: Column (
264
230
mainAxisAlignment: MainAxisAlignment .end,
265
231
children: [
266
- FloatingActionButton (
267
- heroTag: "btn1" ,
268
- backgroundColor: const Color (0xFFFFAB08 ),
269
- foregroundColor: const Color (0xFFFFFFFF ),
270
- child: const Icon (Icons .file_download),
232
+ _LandingPageFAB (
233
+ heroTag: "import_image" ,
234
+ icon: Icons .file_download,
271
235
onPressed: () async {
272
236
final bool imageLoaded =
273
237
await ioHandler.loadImage (context, this , false );
@@ -279,11 +243,9 @@ class _LandingPageState extends ConsumerState<LandingPage> {
279
243
const SizedBox (
280
244
height: 10 ,
281
245
),
282
- FloatingActionButton (
283
- heroTag: "btn2" ,
284
- backgroundColor: const Color (0xFFFFAB08 ),
285
- foregroundColor: const Color (0xFFFFFFFF ),
286
- child: const Icon (Icons .add),
246
+ _LandingPageFAB (
247
+ heroTag: "new_image" ,
248
+ icon: Icons .add,
287
249
onPressed: () async {
288
250
_clearCanvas ();
289
251
_navigateToPocketPaint ();
@@ -294,3 +256,62 @@ class _LandingPageState extends ConsumerState<LandingPage> {
294
256
);
295
257
}
296
258
}
259
+
260
+ class _LandingPageFAB extends StatelessWidget {
261
+ final String heroTag;
262
+ final IconData icon;
263
+ final VoidCallback onPressed;
264
+
265
+ const _LandingPageFAB ({
266
+ Key ? key,
267
+ required this .heroTag,
268
+ required this .icon,
269
+ required this .onPressed,
270
+ }) : super (key: key);
271
+
272
+ @override
273
+ Widget build (BuildContext context) {
274
+ return FloatingActionButton (
275
+ heroTag: heroTag,
276
+ backgroundColor: const Color (0xFFFFAB08 ),
277
+ foregroundColor: const Color (0xFFFFFFFF ),
278
+ child: Icon (icon),
279
+ onPressed: () async => onPressed (),
280
+ );
281
+ }
282
+ }
283
+
284
+ class _ImagePreview extends StatelessWidget {
285
+ final Uint8List ? img;
286
+ final double ? width;
287
+ final Color color;
288
+
289
+ const _ImagePreview ({Key ? key, this .img, this .width, required this .color})
290
+ : super (key: key);
291
+
292
+ ImageProvider _getProjectPreviewImageProvider (Uint8List img) =>
293
+ Image .memory (img, fit: BoxFit .cover).image;
294
+
295
+ @override
296
+ Widget build (BuildContext context) {
297
+ var imgPreview = BoxDecoration (color: color);
298
+ if (img != null ) {
299
+ imgPreview = BoxDecoration (
300
+ color: color,
301
+ image: DecorationImage (
302
+ image: _getProjectPreviewImageProvider (img! ),
303
+ ),
304
+ );
305
+ }
306
+ if (width != null ) {
307
+ return Container (
308
+ width: width! ,
309
+ decoration: imgPreview,
310
+ );
311
+ } else {
312
+ return Container (
313
+ decoration: imgPreview,
314
+ );
315
+ }
316
+ }
317
+ }
0 commit comments