getUserProfile method
- String userID, {
- void onComplete(
- GemError error,
- UserProfile? profile
Gets the locally stored profile of a user.
Parameters
userID: The user.onComplete: Called with GemError.success and the profile, or with GemError.notFound and null when none is stored.
Returns
- The ProgressListener of the call, or null when it could not start.
Implementation
ProgressListener? getUserProfile(
String userID, {
void Function(GemError error, UserProfile? profile)? 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) {
onComplete?.call(GemErrorExtension.fromCode(err), null);
return;
}
// The store answers an empty profile when there is none.
final UserProfile profile = UserProfile.fromJson(json['result']);
if (profile.userID.isEmpty) {
onComplete?.call(GemError.notFound, null);
} else {
onComplete?.call(GemError.success, profile);
}
});
final OperationResult resultString = objectMethod(
pointerId,
'ActivityStore',
'getUserProfile',
args: <String, dynamic>{
'userID': userID,
'listener': progressListener.id,
},
);
final GemError errorCode = GemErrorExtension.fromCode(
resultString['result'],
);
if (errorCode != GemError.success) {
onComplete?.call(errorCode, null);
return null;
}
return progressListener;
}