Skip to content

Commit 4bc0875

Browse files
authored
[MOB-2971] Flutter API: logUserEventWithName: (#39)
1) Adds Api Mapping in Both android and ios 2) Adds Api method in flutter 3) Adds Testing for the API method call 4) Updates README with the method name in flutter
1 parent 20b3f86 commit 4bc0875

File tree

6 files changed

+42
-33
lines changed

6 files changed

+42
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The table below contains a list of APIs we're planning to implement for our 1.0
4040
|`InstabugFlutter.setUserAttributeWithKey(String value, String key)`| `Instabug.getUserAttribute(String key)`<br>`+ [Instabug userAttributeForKey:]` |
4141
|`InstabugFlutter.removeUserAttributeForKey(String key)`| `Instabug.removeUserAttribute(String key)`<br>`+ [Instabug removeUserAttributeForKey:]` |
4242
| | `Instabug.getAllUserAttributes()`<br>`+ [Instabug userAttributes:]` |
43-
| | `Instabug.logUserEvent(String name)`<br>`+ [Instabug logUserEventWithName:]` |
43+
|`logUserEventWithName(String name)`| `Instabug.logUserEvent(String name)`<br>`+ [Instabug logUserEventWithName:]` |
4444
|`show()`| `Instabug.show()`<br>`+ [Instabug show]` |
4545
|`invokeWithMode(InvocationMode invocationMode, [List<InvocationOption> invocationOptions])`| `BugReporting.invoke(InvocationMode mode, @InvocationOption int... options)`<br>`+ [IBGBugReporting invokeWithMode:options:]` |
4646
|`logDebug(String message)`| `InstabugLog.d(String message)`<br>`+ [IBGLog logDebug:]` |

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,14 @@ public void invokeWithMode(String invocationMode, List<String> invocationOptions
299299
int invMode = ArgsRegistry.getDeserializedValue(invocationMode, Integer.class);
300300
BugReporting.show(invMode, options);
301301
}
302+
303+
/**
304+
* Logs a user event that happens through the lifecycle of the application.
305+
* Logged user events are going to be sent with each report, as well as at the end of a session.
306+
*
307+
* @param name Event name.
308+
*/
309+
public void logUserEventWithName(String name) {
310+
Instabug.logUserEvent(name);
311+
}
302312
}

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class _MyAppState extends State<MyApp> {
4444
InstabugFlutter.setUserAttributeWithKey('19', 'Age');
4545
InstabugFlutter.setUserAttributeWithKey('female', 'gender');
4646
InstabugFlutter.removeUserAttributeForKey('gender');
47+
InstabugFlutter.logUserEventWithName('Aly Event');
4748

4849
} on PlatformException {
4950
platformVersion = 'Failed to get platform version.';

example/test/main.dart

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,8 @@ void main() {
1818
.setMockMethodCallHandler((MethodCall methodCall) async {
1919
log.add(methodCall);
2020
switch (methodCall.method) {
21-
case 'startWithToken:invocationEvents:':
22-
return null;
23-
case 'showWelcomeMessageWithMode:':
24-
return null;
25-
case 'identifyUserWithEmail:':
26-
return null;
27-
case 'logOut':
28-
return null;
29-
case 'setLocale:':
30-
return null;
31-
case 'logVerbose:':
32-
return null;
33-
case 'logDebug:':
34-
return null;
35-
case 'logInfo:':
36-
return null;
37-
case 'clearAllLogs:':
38-
return null;
39-
case 'logError:':
40-
return null;
41-
case 'logWarn:':
42-
return null;
43-
case 'setColorTheme:':
44-
return null;
4521
case 'getTags':
4622
return ['tag1', 'tag2'];
47-
case 'setUserAttribute:withKey:':
48-
return null;
49-
case 'removeUserAttributeForKey:':
50-
return null;
51-
case 'show':
52-
return null;
53-
case 'invokeWithMode:options:':
54-
return null;
5523
default:
5624
return null;
5725
}
@@ -252,6 +220,7 @@ test('startWithToken:invocationEvents: Test', () async {
252220
]);
253221
});
254222

223+
255224
test('invokeWithMode:options: Test', () async {
256225
InstabugFlutter.invokeWithMode(InvocationMode.BUG, [InvocationOption.COMMENT_FIELD_REQUIRED]);
257226
final List<dynamic> args = <dynamic>[InvocationMode.BUG.toString(), <String>[InvocationOption.COMMENT_FIELD_REQUIRED.toString()]];
@@ -262,6 +231,16 @@ test('startWithToken:invocationEvents: Test', () async {
262231
]);
263232
});
264233

234+
test('logUserEventWithName: Test', () async {
235+
InstabugFlutter.logUserEventWithName(name);
236+
final List<dynamic> args = <dynamic>[name];
237+
expect(log, <Matcher>[
238+
isMethodCall('logUserEventWithName:',
239+
arguments: args,
240+
)
241+
]);
242+
});
243+
265244
}
266245

267246

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@ + (void) invokeWithMode:(NSString *)invocationMode options:(NSArray*)invocationO
250250
[IBGBugReporting showWithReportType:invocation options:invocationOptions];
251251
}
252252

253+
/**
254+
* Logs a user event that happens through the lifecycle of the application.
255+
* Logged user events are going to be sent with each report, as well as at the end of a session.
256+
*
257+
* @param name Event name.
258+
*/
259+
+ (void) logUserEventWithName:(NSString *) name {
260+
[Instabug logUserEventWithName:name];
261+
}
262+
253263
+ (NSDictionary *)constants {
254264
return @{
255265
@"InvocationEvent.shake": @(IBGInvocationEventShake),

lib/instabug_flutter.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,13 @@ class InstabugFlutter {
218218
final List<dynamic> params = <dynamic>[invocationMode.toString(), invocationOptionsStrings];
219219
await _channel.invokeMethod<Object>('invokeWithMode:options:',params);
220220
}
221+
222+
/// Logs a user event with [name] that happens through the lifecycle of the application.
223+
/// Logged user events are going to be sent with each report, as well as at the end of a session.
224+
static void logUserEventWithName(String name) async {
225+
final List<String> params = <String>[name];
226+
await _channel.invokeMethod<Object>('logUserEventWithName:', params);
227+
}
221228
}
229+
230+

0 commit comments

Comments
 (0)