Skip to content

Commit

Permalink
added error and complete block
Browse files Browse the repository at this point in the history
  • Loading branch information
mehsaandev committed Jan 15, 2025
1 parent aff857b commit 51b1360
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/ensemble/lib/action/action_invokable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class ActionInvokable with Invokable {
ActionType.dismissDialog,
ActionType.closeAllDialogs,
ActionType.executeActionGroup,
ActionType.takeScreenshot
ActionType.takeScreenshot,
ActionType.saveFile,
ActionType.controlDeviceBackNavigation,
ActionType.closeApp,
Expand Down
30 changes: 29 additions & 1 deletion modules/ensemble/lib/action/saveFile/save_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import 'dart:convert';
import 'dart:typed_data';

import 'package:ensemble/framework/action.dart';
import 'package:ensemble/framework/event.dart';
import 'package:ensemble/framework/scope.dart';
import 'package:ensemble/screen_controller.dart';
import 'package:flutter/material.dart';
import 'package:ensemble/framework/error_handling.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -15,12 +17,16 @@ class SaveToFileSystemAction extends EnsembleAction {
final dynamic blobData;
final String? source; // Optional source for URL if blobData is not available
final String? type; // file type
final EnsembleAction? onComplete;
final EnsembleAction? onError;

SaveToFileSystemAction({
required this.fileName,
this.blobData,
this.source,
this.type,
this.onComplete,
this.onError,
});

factory SaveToFileSystemAction.from({Map? payload}) {
Expand All @@ -33,6 +39,12 @@ class SaveToFileSystemAction extends EnsembleAction {
blobData: payload['blobData'],
source: payload['source'],
type: payload['type'],
onComplete: payload['onComplete'] != null
? EnsembleAction.from(payload['onComplete'])
: null,
onError: payload['onError'] != null
? EnsembleAction.from(payload['onComplete'])
: null,
);
}

Expand Down Expand Up @@ -71,8 +83,24 @@ class SaveToFileSystemAction extends EnsembleAction {

// Save the file to the storage system
await _saveFile(type!, fileName!, fileBytes);
if (onComplete != null) {
await ScreenController().executeAction(
context,
onComplete!,
event: EnsembleEvent(initiator, data: {
'fileBytes': fileBytes,
'fileName': fileName,
}),
);
}
} catch (e) {
throw Exception('Failed to save file: $e');
if (onError != null) {
await ScreenController().executeAction(
context,
onError!,
event: EnsembleEvent(initiator, data: {'error': e.toString()}),
);
}
}
}

Expand Down

0 comments on commit 51b1360

Please sign in to comment.