forked from fossasia/magic-epaper-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_editor.dart
More file actions
105 lines (98 loc) · 3.19 KB
/
image_editor.dart
File metadata and controls
105 lines (98 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:magic_epaper_app/pro_image_editor/features/movable_background_image.dart';
import 'package:magic_epaper_app/view/widget/image_list.dart';
import 'package:provider/provider.dart';
import 'package:image/image.dart' as img;
import 'package:magic_epaper_app/provider/image_loader.dart';
import 'package:magic_epaper_app/util/epd/epd.dart';
import 'package:magic_epaper_app/constants.dart';
class ImageEditor extends StatelessWidget {
final Epd epd;
const ImageEditor({super.key, required this.epd});
@override
Widget build(BuildContext context) {
var imgLoader = context.watch<ImageLoader>();
final List<img.Image> processedImgs = List.empty(growable: true);
final orgImg = imgLoader.image;
if (orgImg != null) {
final image = img.copyResize(imgLoader.image!,
width: epd.width, height: epd.height);
for (final method in epd.processingMethods) {
processedImgs.add(method(image));
}
}
final imgList = ImageList(
imgList: processedImgs,
epd: epd,
);
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
iconTheme: const IconThemeData(
color: Colors.white,
),
backgroundColor: colorAccent,
elevation: 0,
title: const Center(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Text(
'Select Your Filter',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
toolbarHeight: 85,
actions: <Widget>[
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.white.withValues(alpha: 0.2),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
onPressed: () {
imgLoader.pickImage(width: epd.width, height: epd.height);
},
child: const Text(
"Import Image",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
TextButton(
onPressed: () async {
final canvasBytes = await Navigator.of(context).push<Uint8List>(
MaterialPageRoute(
builder: (context) => const MovableBackgroundImageExample(),
),
);
imgLoader.updateImage(
bytes: canvasBytes!,
width: epd.width,
height: epd.height,
);
},
child: const Text("Open Editor"),
),
],
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: imgList,
),
),
);
}
}