@@ -28,6 +28,20 @@ class _ImageEditorState extends State<ImageEditor> {
2828 List <img.Image > _rawImages = [];
2929 List <Uint8List > _processedPngs = [];
3030
31+ @override
32+ void initState () {
33+ super .initState ();
34+ Future .microtask (() {
35+ final imgLoader = context.read <ImageLoader >();
36+ if (imgLoader.image == null ) {
37+ imgLoader.loadFinalizedImage (
38+ width: widget.epd.width,
39+ height: widget.epd.height,
40+ );
41+ }
42+ });
43+ }
44+
3145 void _onFilterSelected (int index) {
3246 if (_selectedFilterIndex != index) {
3347 setState (() {
@@ -127,29 +141,36 @@ class _ImageEditorState extends State<ImageEditor> {
127141 ),
128142 ],
129143 ),
130- body: SafeArea (
131- child: Padding (
132- padding: const EdgeInsets .symmetric (horizontal: 8.0 ),
133- child: _processedPngs.isNotEmpty
134- ? ImageList (
135- key: ValueKey (_processedSourceImage),
136- processedPngs: _processedPngs,
137- epd: widget.epd,
138- selectedIndex: _selectedFilterIndex,
139- flipHorizontal: flipHorizontal,
140- flipVertical: flipVertical,
141- onFilterSelected: _onFilterSelected,
142- onFlipHorizontal: toggleFlipHorizontal,
143- onFlipVertical: toggleFlipVertical,
144- )
145- : const Center (
146- child: Text (
147- "Import an image to begin" ,
148- style: TextStyle (color: Colors .grey, fontSize: 16 ),
149- ),
150- ),
151- ),
152- ),
144+ body: imgLoader.isLoading
145+ ? const Center (
146+ child: Text ('Loading...' ,
147+ style: TextStyle (
148+ color: colorBlack,
149+ fontSize: 14 ,
150+ )))
151+ : SafeArea (
152+ child: Padding (
153+ padding: const EdgeInsets .symmetric (horizontal: 8.0 ),
154+ child: _processedPngs.isNotEmpty
155+ ? ImageList (
156+ key: ValueKey (_processedSourceImage),
157+ processedPngs: _processedPngs,
158+ epd: widget.epd,
159+ selectedIndex: _selectedFilterIndex,
160+ flipHorizontal: flipHorizontal,
161+ flipVertical: flipVertical,
162+ onFilterSelected: _onFilterSelected,
163+ onFlipHorizontal: toggleFlipHorizontal,
164+ onFlipVertical: toggleFlipVertical,
165+ )
166+ : const Center (
167+ child: Text (
168+ "Import an image to begin" ,
169+ style: TextStyle (color: Colors .grey, fontSize: 16 ),
170+ ),
171+ ),
172+ ),
173+ ),
153174 bottomNavigationBar: BottomActionMenu (
154175 epd: widget.epd,
155176 imgLoader: imgLoader,
@@ -193,8 +214,14 @@ class BottomActionMenu extends StatelessWidget {
193214 context: context,
194215 icon: Icons .add_photo_alternate_outlined,
195216 label: 'Import New' ,
196- onTap: () {
197- imgLoader.pickImage (width: epd.width, height: epd.height);
217+ onTap: () async {
218+ final success = await imgLoader.pickImage (
219+ width: epd.width, height: epd.height);
220+ if (success && imgLoader.image != null ) {
221+ final bytes =
222+ Uint8List .fromList (img.encodePng (imgLoader.image! ));
223+ await imgLoader.saveFinalizedImageBytes (bytes);
224+ }
198225 },
199226 ),
200227 _buildActionButton (
@@ -210,11 +237,12 @@ class BottomActionMenu extends StatelessWidget {
210237 ),
211238 );
212239 if (canvasBytes != null ) {
213- imgLoader.updateImage (
240+ await imgLoader.updateImage (
214241 bytes: canvasBytes,
215242 width: epd.width,
216243 height: epd.height,
217244 );
245+ await imgLoader.saveFinalizedImageBytes (canvasBytes);
218246 }
219247 },
220248 ),
0 commit comments