Skip to content

Commit 2c2ac43

Browse files
authored
Merge pull request #95 from fluttercandies/add-doc
doc: Add api document for dart classes
2 parents 62b7025 + 8133b30 commit 2c2ac43

23 files changed

+282
-11
lines changed

example/lib/draw_example_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ class _DrawExamplePageState extends State<DrawExamplePage> {
190190
paint: paint,
191191
);
192192
path.move(Offset.zero);
193-
path.lineTo(randomOffset(), paint);
194-
path.lineTo(randomOffset(), paint);
193+
path.lineTo(randomOffset());
194+
path.lineTo(randomOffset());
195195
path.bezier2To(randomOffset(), randomOffset());
196196
path.bezier3To(randomOffset(), randomOffset(), randomOffset());
197197
await addDrawPart(path);

lib/src/channel.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ import 'package:flutter/services.dart';
55

66
import 'option/edit_options.dart';
77

8+
/// Wrapper for [MethodChannel].
89
class NativeChannel {
910
const NativeChannel._();
1011

12+
/// The channel for use native method.
1113
static const MethodChannel channel = MethodChannel(
1214
'com.fluttercandies/image_editor',
1315
);
1416

17+
/// Get the cache directory path.
1518
static Future<Directory> getCachePath() async {
1619
final path = await channel.invokeMethod('getCachePath');
1720
return Directory(path);
1821
}
1922

23+
/// Handle memory source and get file result.
2024
static Future<String> memoryToFile(
2125
Uint8List memory,
2226
ImageEditorOption option,
@@ -33,6 +37,7 @@ class NativeChannel {
3337
});
3438
}
3539

40+
/// Handle memory source and get momory result.
3641
static Future<Uint8List> memoryToMemory(
3742
Uint8List memory,
3843
ImageEditorOption option,
@@ -49,6 +54,7 @@ class NativeChannel {
4954
return result;
5055
}
5156

57+
/// Handle file source and get momory result.
5258
static Future<Uint8List> fileToMemory(
5359
String path,
5460
ImageEditorOption option,
@@ -64,6 +70,7 @@ class NativeChannel {
6470
});
6571
}
6672

73+
/// Handle file source and get file result.
6774
static Future<String> fileToFile(
6875
String src,
6976
ImageEditorOption option,

lib/src/convert_value.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import 'package:flutter/services.dart';
2+
3+
/// Used to describe fields that can be JSON,
4+
/// mainly used for [MethodChannel] invoke.
15
mixin JsonAble {
6+
/// Convert current instance to [Map].
27
Map<String, Object?> toJson();
38
}

lib/src/editor.dart

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ import 'channel.dart';
66
import 'image_handler.dart';
77
import 'option/edit_options.dart';
88

9+
/// The main class of ImageEditor plugin.
910
class ImageEditor {
1011
const ImageEditor._();
1112

12-
/// [image] Uint8List
13-
/// [imageEditorOption] option of
13+
/// The [image] is a source of image.
14+
///
15+
/// The [imageEditorOption] option for edit image.
16+
///
17+
/// The method will return a [Uint8List] as image result.
18+
///
19+
/// If result is null, it means handle image error.
1420
static Future<Uint8List?> editImage({
1521
required Uint8List image,
1622
required ImageEditorOption imageEditorOption,
@@ -31,6 +37,13 @@ class ImageEditor {
3137
return tmp;
3238
}
3339

40+
/// The [file] is the source of image.
41+
///
42+
/// The [imageEditorOption] is the option for edit image.
43+
///
44+
/// The method will return a [Uint8List] as image result.
45+
///
46+
/// If result is null, it means handle image error.
3447
static Future<Uint8List?> editFileImage({
3548
required File file,
3649
required ImageEditorOption imageEditorOption,
@@ -57,6 +70,13 @@ class ImageEditor {
5770
}
5871
}
5972

73+
/// The [file] is the source of image.
74+
///
75+
/// The [imageEditorOption] is the option for edit image.
76+
///
77+
/// The method will return a [File] as image result.
78+
///
79+
/// If result is null, it means handle image error.
6080
static Future<File?> editFileImageAndGetFile({
6181
required File file,
6282
required ImageEditorOption imageEditorOption,
@@ -78,6 +98,13 @@ class ImageEditor {
7898
return tmp;
7999
}
80100

101+
/// The [image] is the source of image.
102+
///
103+
/// The [imageEditorOption] is the option for edit image.
104+
///
105+
/// The method will return a [File] as image result.
106+
///
107+
/// If result is null, it means handle image error.
81108
static Future<File> editImageAndGetFile({
82109
required Uint8List image,
83110
required ImageEditorOption imageEditorOption,
@@ -102,6 +129,7 @@ class ImageEditor {
102129
return file;
103130
}
104131

132+
/// The method will create a temp file path.
105133
static Future<String> _createTmpFilePath() async {
106134
final cacheDir = await NativeChannel.getCachePath();
107135
final name = DateTime.now().millisecondsSinceEpoch;

lib/src/error.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
/// Error for handle image.
12
class HandleError implements Exception {
3+
/// Error for handle image.
24
HandleError([this.msg = '']);
35

6+
/// The message of error.
47
final String msg;
58

69
@override

lib/src/font_manager.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:io';
22

33
import 'channel.dart';
44

5+
/// Wrapper for use channel to register font for add text.
56
class FontManager {
67
const FontManager._();
78

lib/src/image_handler.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'error.dart';
66
import 'option/edit_options.dart';
77
import 'type.dart';
88

9+
/// Wrapper for use channel to handle image.
910
class ImageHandler {
1011
ImageHandler.memory(this._memory)
1112
: _type = SrcType.memory,

lib/src/image_source.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,50 @@ import 'dart:typed_data';
33

44
import 'convert_value.dart';
55

6+
/// Used to describe the source of an image.
67
abstract class ImageSource with JsonAble {
8+
/// Used to describe the source of an image.
79
const ImageSource();
810

11+
/// Used to describe the memory image.
912
factory ImageSource.memory(Uint8List uint8list) {
1013
return MemoryImageSource(uint8list);
1114
}
1215

16+
/// Used to describe the file image.
1317
factory ImageSource.file(File file) {
1418
return FileImageSource(file);
1519
}
1620

21+
/// Used to describe the file image.
1722
factory ImageSource.path(String path) {
1823
return FileImageSource.path(path);
1924
}
2025

26+
/// The image data as [Uint8List].
2127
Uint8List get memory;
2228

2329
@override
2430
Map<String, Object?> toJson() => <String, Object?>{'memory': memory};
2531
}
2632

33+
/// The memory image source.
2734
class MemoryImageSource extends ImageSource {
2835
const MemoryImageSource(Uint8List uint8list) : memory = uint8list;
2936

3037
@override
3138
final Uint8List memory;
3239
}
3340

41+
/// The file image source.
3442
class FileImageSource extends ImageSource {
43+
/// Use [file] to create image source.
3544
const FileImageSource(this.file);
3645

46+
/// Use [path] to create image source.
3747
FileImageSource.path(String path) : file = File(path);
3848

49+
/// The file of image.
3950
final File file;
4051

4152
@override

lib/src/merge/image_merger.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import 'package:image_editor/src/channel.dart';
55

66
import 'merge_option.dart';
77

8+
/// Use the class to merge multiple images.
89
class ImageMerger {
910
const ImageMerger._();
1011

12+
/// Merge multiple images.
1113
static Future<Uint8List?> mergeToMemory({required ImageMergeOption option}) {
1214
return NativeChannel.channel.invokeMethod('mergeToMemory', {
1315
'option': option.toJson(),
1416
});
1517
}
1618

19+
/// Merge multiple images and get file.
1720
static Future<File?> mergeToFile({required ImageMergeOption option}) {
1821
return NativeChannel.channel.invokeMethod('mergeToFile', {
1922
'option': option.toJson(),

lib/src/merge/merge_option.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@ import '../image_source.dart';
55
import '../output_format.dart';
66
import '../position.dart';
77

8+
/// Merge multiple images option.
89
class ImageMergeOption with JsonAble {
910
ImageMergeOption({
1011
required this.canvasSize,
1112
this.format = const OutputFormat.jpeg(90),
1213
}) : assert(canvasSize > Size.zero);
1314

15+
/// The canvas size. (output image size)
1416
final Size canvasSize;
17+
18+
/// Output format for result image.
1519
final OutputFormat format;
1620

21+
/// All merge image options.
1722
final List<MergeImageConfig> _mergeImageConfig = <MergeImageConfig>[];
1823

24+
/// Add a merge image option.
1925
void addImage(MergeImageConfig config) {
2026
_mergeImageConfig.add(config);
2127
}
@@ -31,13 +37,18 @@ class ImageMergeOption with JsonAble {
3137
}
3238
}
3339

40+
/// Merge image option.
3441
class MergeImageConfig with JsonAble {
42+
/// Merge image option.
3543
const MergeImageConfig({
3644
required this.image,
3745
required this.position,
3846
});
3947

48+
/// The image source.
4049
final ImageSource image;
50+
51+
/// The position of image.
4152
final ImagePosition position;
4253

4354
@override

0 commit comments

Comments
 (0)