Skip to content

Commit c34866a

Browse files
committed
fix: resolve merge conflicts.
1 parent 998be5a commit c34866a

File tree

1 file changed

+54
-52
lines changed

1 file changed

+54
-52
lines changed

lib/view/image_editor.dart

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,6 @@ class ImageEditor extends StatefulWidget {
1919
State<ImageEditor> createState() => _ImageEditorState();
2020
}
2121

22-
class _ImageEditorState extends State<ImageEditor> {
23-
bool flipHorizontal = false;
24-
bool flipVertical = false;
25-
26-
void toggleFlipHorizontal() {
27-
setState(() {
28-
flipHorizontal = !flipHorizontal;
29-
});
30-
}
31-
32-
void toggleFlipVertical() {
33-
setState(() {
34-
flipVertical = !flipVertical;
35-
});
36-
}
37-
38-
@override
39-
State<ImageEditor> createState() => _ImageEditorState();
40-
}
41-
4222
class _ImageEditorState extends State<ImageEditor> {
4323
int _selectedFilterIndex = 0;
4424
bool flipHorizontal = false;
@@ -48,6 +28,20 @@ class _ImageEditorState extends State<ImageEditor> {
4828
List<img.Image> _rawImages = [];
4929
List<Uint8List> _processedPngs = [];
5030

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+
5145
void _onFilterSelected(int index) {
5246
if (_selectedFilterIndex != index) {
5347
setState(() {
@@ -147,35 +141,36 @@ class _ImageEditorState extends State<ImageEditor> {
147141
),
148142
],
149143
),
150-
floatingActionButton: orgImg != null
151-
? FlipControls(
152-
onFlipHorizontal: toggleFlipHorizontal,
153-
onFlipVertical: toggleFlipVertical,
154-
)
155-
: null,
156-
body: SafeArea(
157-
child: Padding(
158-
padding: const EdgeInsets.symmetric(horizontal: 8.0),
159-
child: _processedPngs.isNotEmpty
160-
? ImageList(
161-
key: ValueKey(_processedSourceImage),
162-
processedPngs: _processedPngs,
163-
epd: widget.epd,
164-
selectedIndex: _selectedFilterIndex,
165-
flipHorizontal: flipHorizontal,
166-
flipVertical: flipVertical,
167-
onFilterSelected: _onFilterSelected,
168-
onFlipHorizontal: toggleFlipHorizontal,
169-
onFlipVertical: toggleFlipVertical,
170-
)
171-
: const Center(
172-
child: Text(
173-
"Import an image to begin",
174-
style: TextStyle(color: Colors.grey, fontSize: 16),
175-
),
176-
),
177-
),
178-
),
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+
),
179174
bottomNavigationBar: BottomActionMenu(
180175
epd: widget.epd,
181176
imgLoader: imgLoader,
@@ -219,8 +214,14 @@ class BottomActionMenu extends StatelessWidget {
219214
context: context,
220215
icon: Icons.add_photo_alternate_outlined,
221216
label: 'Import New',
222-
onTap: () {
223-
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+
}
224225
},
225226
),
226227
_buildActionButton(
@@ -236,11 +237,12 @@ class BottomActionMenu extends StatelessWidget {
236237
),
237238
);
238239
if (canvasBytes != null) {
239-
imgLoader.updateImage(
240+
await imgLoader.updateImage(
240241
bytes: canvasBytes,
241242
width: epd.width,
242243
height: epd.height,
243244
);
245+
await imgLoader.saveFinalizedImageBytes(canvasBytes);
244246
}
245247
},
246248
),

0 commit comments

Comments
 (0)