listLocalActivities method
Lists the local activities of a user, newest first.
Parameters
userID: The user.onComplete: Called with GemError.success and the activities, empty when the user has none.
Returns
- The ProgressListener of the call, or null when it could not start.
Implementation
ProgressListener? listLocalActivities(
String userID, {
void Function(GemError error, List<Activity> activities)? onComplete,
}) {
final EventDrivenProgressListener progressListener =
EventDrivenProgressListener();
GemKitPlatform.instance.registerEventHandler(
progressListener.id,
progressListener,
);
progressListener.registerOnCompleteWithData((
int err,
String hint,
Map<dynamic, dynamic> json,
) {
GemKitPlatform.instance.unregisterEventHandler(progressListener.id);
if (err == 0) {
final List<Activity> activities = (json['result'] as List<dynamic>)
.map((dynamic activity) => Activity.fromJson(activity))
.toList();
onComplete?.call(GemErrorExtension.fromCode(err), activities);
} else {
onComplete?.call(GemErrorExtension.fromCode(err), <Activity>[]);
}
});
final OperationResult resultString = objectMethod(
pointerId,
'ActivityStore',
'listLocalActivities',
args: <String, dynamic>{
'userID': userID,
'listener': progressListener.id,
},
);
final GemError errorCode = GemErrorExtension.fromCode(
resultString['result'],
);
if (errorCode != GemError.success) {
onComplete?.call(errorCode, <Activity>[]);
return null;
}
return progressListener;
}