Skip to content

Commit b02faf7

Browse files
authored
[Mob 3189] - [MOB-3191]: Flutter API: FileAttachments (#55)
Android API Mappings IOS API Mapping Flutter API Mapping Adds tests for new API updates Readme updated Changelog
1 parent 9044a9c commit b02faf7

File tree

7 files changed

+141
-4
lines changed

7 files changed

+141
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Master
22

3+
* Adds addFileAttachmentWithURL, addFileAttachmentWithData, clearFileAttachments API mapping.
34
* Adds setUserData API mapping.
45
* Adds setPrimaryColor API mapping.
56
* Adds setSessionProfilerEnabled API mapping.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ The section below contains the APIs we're planning to implement for our 1.0 rele
4646
|`setPrimaryColor(Color color)` | `setPrimaryColor(@ColorInt int primaryColorValue)`<br>`tintColor` |
4747
| | `onReportSubmitHandler(Report.OnReportCreatedListener listener)`<br>`willSendReportHandler`. |
4848
|`setUserData(String userData)` | `setUserData(String userData)`<br>`userData` |
49-
| | `addFileAttachment(Uri fileUri, String fileNameWithExtension)`<br>`+ addFileAttachmentWithURL:` |
50-
| | `addFileAttachment(byte[] data, String fileNameWithExtension)` `+ addFileAttachmentWithData:` |
51-
| | `clearFileAttachment()`<br>`+ clearFileAttachments` |
49+
| `addFileAttachmentWithURL(String filePath, String fileName)` | `addFileAttachment(Uri fileUri, String fileNameWithExtension)`<br>`+ addFileAttachmentWithURL:` |
50+
| `addFileAttachmentWithData(Uint8List data, String fileName)` | `addFileAttachment(byte[] data, String fileNameWithExtension)` `+ addFileAttachmentWithData:` |
51+
| `clearFileAttachments()` | `clearFileAttachment()`<br>`+ clearFileAttachments` |
5252
| | `setWelcomeMessageState(WelcomeMessage.State welcomeMessageState)`<br>`welcomeMessageMode` |
5353

5454
#### `BugReporting`

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.instabug.instabugflutter;
22

33
import android.app.Application;
4+
import android.net.Uri;
45
import android.os.Handler;
56
import android.os.Looper;
67
import android.util.Log;
@@ -17,6 +18,7 @@
1718
import com.instabug.library.logging.InstabugLog;
1819
import com.instabug.library.ui.onboarding.WelcomeMessage;
1920

21+
import java.io.File;
2022
import java.lang.reflect.InvocationTargetException;
2123
import java.lang.reflect.Method;
2224
import java.util.ArrayList;
@@ -423,4 +425,38 @@ public void run() {
423425
public void setUserData(String userData) {
424426
Instabug.setUserData(userData);
425427
}
428+
429+
/**
430+
* The file at filePath will be uploaded along upcoming reports with the name
431+
* fileNameWithExtension
432+
*
433+
* @param fileUri the file uri
434+
* @param fileNameWithExtension the file name with extension
435+
*/
436+
public void addFileAttachmentWithURL(String fileUri, String fileNameWithExtension) {
437+
File file = new File(fileUri);
438+
if (file.exists()) {
439+
Instabug.addFileAttachment(Uri.fromFile(file), fileNameWithExtension);
440+
}
441+
}
442+
443+
444+
/**
445+
* The file at filePath will be uploaded along upcoming reports with the name
446+
* fileNameWithExtension
447+
*
448+
* @param data the data of the file
449+
* @param fileNameWithExtension the file name with extension
450+
*/
451+
public void addFileAttachmentWithData(byte[] data, String fileNameWithExtension) {
452+
Instabug.addFileAttachment(data, fileNameWithExtension);
453+
}
454+
455+
/**
456+
* Clears all Uris of the attached files.
457+
* The URIs which added via {@link Instabug#addFileAttachment} API not the physical files.
458+
*/
459+
public void clearFileAttachments() {
460+
Instabug.clearFileAttachment();
461+
}
426462
}

example/lib/main.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22
import 'dart:io' show Platform;
3+
import 'dart:typed_data';
34
import 'package:flutter/material.dart';
45
import 'package:flutter/services.dart';
56
import 'package:instabug_flutter/Instabug.dart';
@@ -54,9 +55,12 @@ class _MyAppState extends State<MyApp> {
5455
Instabug.setValueForStringWithKey('Send some ideas', IBGCustomTextPlaceHolderKey.REPORT_FEEDBACK);
5556
Instabug.setSessionProfilerEnabled(false);
5657
Color c = const Color.fromRGBO(255, 0, 255, 1.0);
57-
Color c = const Color.fromRGBO(255, 0, 0, 1.0);
5858
Instabug.setPrimaryColor(c);
5959
Instabug.setUserData("This is some useful data");
60+
var list = Uint8List(10);
61+
Instabug.addFileAttachmentWithData(list, "My File");
62+
Instabug.clearFileAttachments();
63+
//Instabug.clearFileAttachments();
6064
} on PlatformException {
6165
platformVersion = 'Failed to get platform version.';
6266
}

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,34 @@ + (void)setUserData:(NSString *)userData {
319319
[Instabug setUserData:userData];
320320
}
321321

322+
/**
323+
* The file at filePath will be uploaded along upcoming reports with the name
324+
* fileNameWithExtension
325+
*
326+
* @param fileUri the file uri
327+
*/
328+
+ (void)addFileAttachmentWithURL:(NSString *)fileURLString {
329+
[Instabug addFileAttachmentWithURL:[NSURL URLWithString:fileURLString]];
330+
}
331+
332+
/**
333+
* The file at filePath will be uploaded along upcoming reports with the name
334+
* fileNameWithExtension
335+
*
336+
* @param data the file data
337+
*/
338+
+ (void)addFileAttachmentWithData:(FlutterStandardTypedData *)data {
339+
[Instabug addFileAttachmentWithData:[data data]];
340+
}
341+
342+
/**
343+
* Clears all Uris of the attached files.
344+
* The URIs which added via {@link Instabug#addFileAttachment} API not the physical files.
345+
*/
346+
+ (void)clearFileAttachments {
347+
[Instabug clearFileAttachments];
348+
}
349+
322350

323351
+ (NSDictionary *)constants {
324352
return @{

lib/Instabug.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'dart:async';
2+
import 'dart:typed_data';
23
import 'dart:ui';
4+
import 'dart:io' show Platform;
35
import 'package:flutter/services.dart';
46

57
enum InvocationEvent {
@@ -227,6 +229,38 @@ class Instabug {
227229
await _channel.invokeMethod<Object>('setUserData:', params);
228230
}
229231

232+
///Add file to be attached to the bug report.
233+
///[filePath] of the file
234+
///[fileName] of the file
235+
static void addFileAttachmentWithURL(String filePath, String fileName) async {
236+
if (Platform.isIOS) {
237+
final List<dynamic> params = <dynamic>[filePath];
238+
await _channel.invokeMethod<Object>('addFileAttachmentWithURL:', params);
239+
} else {
240+
final List<dynamic> params = <dynamic>[filePath,fileName];
241+
await _channel.invokeMethod<Object>('addFileAttachmentWithURL:', params);
242+
}
243+
}
244+
245+
///Add file to be attached to the bug report.
246+
///[data] of the file
247+
///[fileName] of the file
248+
static void addFileAttachmentWithData(Uint8List data, String fileName) async {
249+
if (Platform.isIOS) {
250+
final List<dynamic> params = <dynamic>[data];
251+
await _channel.invokeMethod<Object>('addFileAttachmentWithData:', params);
252+
} else {
253+
final List<dynamic> params = <dynamic>[data,fileName];
254+
await _channel.invokeMethod<Object>('addFileAttachmentWithData:', params);
255+
}
256+
}
257+
258+
///Clears all Uris of the attached files.
259+
///The URIs which added via {@link Instabug#addFileAttachment} API not the physical files.
260+
static void clearFileAttachments() async {
261+
await _channel.invokeMethod<Object>('clearFileAttachments');
262+
}
263+
230264
}
231265

232266

test/instabug_flutter_test.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:io';
2+
import 'dart:typed_data';
23
import 'dart:ui';
34

45
import 'package:instabug_flutter/Instabug.dart';
@@ -317,6 +318,39 @@ test('startWithToken:invocationEvents: Test', () async {
317318
]);
318319
});
319320

321+
test('addFileAttachmentWithURL: Test', () async {
322+
String filePath = "filePath";
323+
String fileName = "fileName";
324+
final List<dynamic> args = <dynamic>[filePath, fileName];
325+
Instabug.addFileAttachmentWithURL(filePath,fileName);
326+
expect(log, <Matcher>[
327+
isMethodCall('addFileAttachmentWithURL:',
328+
arguments: args,
329+
)
330+
]);
331+
});
332+
333+
test('addFileAttachmentWithData: Test', () async {
334+
var bdata = new Uint8List(10);
335+
String fileName = "fileName";
336+
final List<dynamic> args = <dynamic>[bdata, fileName];
337+
Instabug.addFileAttachmentWithData(bdata,fileName);
338+
expect(log, <Matcher>[
339+
isMethodCall('addFileAttachmentWithData:',
340+
arguments: args,
341+
)
342+
]);
343+
});
344+
345+
test('clearFileAttachments Test', () async {
346+
Instabug.clearFileAttachments();
347+
expect(log, <Matcher>[
348+
isMethodCall('clearFileAttachments',
349+
arguments: null,
350+
)
351+
]);
352+
});
353+
320354
}
321355

322356

0 commit comments

Comments
 (0)