Skip to content

Commit

Permalink
feat: update callback data
Browse files Browse the repository at this point in the history
  • Loading branch information
tranhieu1998-it committed Sep 30, 2024
1 parent a622173 commit 5943dcd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>12.0</string>
</dict>
</plist>
13 changes: 8 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -171,10 +171,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -272,7 +275,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -346,7 +349,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -395,7 +398,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
4 changes: 4 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
8 changes: 5 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _MyHomePageState extends State<MyHomePage> {
bool _recording = false;
bool _exporting = false;
ScreenRecorderController controller = ScreenRecorderController();

bool get canExport => controller.exporter.hasFrames;

@override
Expand Down Expand Up @@ -108,8 +109,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: ListView.builder(
padding: const EdgeInsets.all(8.0),
itemCount: frames.length,
itemBuilder:
(BuildContext context, int index) {
itemBuilder: (BuildContext context, int index) {
final image = frames[index].image;
return SizedBox(
height: 150,
Expand All @@ -135,7 +135,9 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() {
_exporting = true;
});
var gif = await controller.exporter.exportGif();
var gif = await controller.exporter.exportGif(percentProcess: (percent) {
print('Exporting $percent');
});
if (gif == null) {
throw Exception();
}
Expand Down
14 changes: 10 additions & 4 deletions lib/src/exporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class Exporter {
return bytesImages;
}

Future<List<int>?> exportGif() async {
Future<List<int>?> exportGif({ValueChanged<double>? percentProcess}) async {
final frames = await exportFrames();
if (frames == null) {
return null;
}
return compute(_exportGif, DataHolder(frames, _maxWidthFrame, _maxHeightFrame));
return compute(_exportGif, DataHolder(frames, _maxWidthFrame, _maxHeightFrame,percentProcess ));
}

static Future<List<int>?> _exportGif(DataHolder data) async {
Expand All @@ -63,8 +63,12 @@ class Exporter {
int height = data.height;

image.Image mainImage = image.Image.empty();

int i =1;
int max = frames.length;
for (final frame in frames) {
double percent = double.parse((i / max).toStringAsFixed(4));
data.percentProcess?.call(percent);
i+=1;
final iAsBytes = frame.image.buffer.asUint8List();
final decodedImage = image.decodePng(iAsBytes);

Expand Down Expand Up @@ -116,6 +120,7 @@ class Exporter {
// a transparency threshold.
final numFrames = srcImage.frames.length;
for (var frameIndex = 0; frameIndex < numFrames; frameIndex++) {

final srcFrame = srcImage.frames[frameIndex];
final newFrame = newImage.frames[frameIndex];

Expand Down Expand Up @@ -143,7 +148,8 @@ class RawFrame {
}

class DataHolder {
DataHolder(this.frames, this.width, this.height);
DataHolder(this.frames, this.width, this.height, this.percentProcess);
ValueChanged<double>? percentProcess;

List<RawFrame> frames;

Expand Down

0 comments on commit 5943dcd

Please sign in to comment.