-
-
Notifications
You must be signed in to change notification settings - Fork 205
Casting current user to custom object #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey Simply add '''await'''' keyword before ''''ParseUser.currentUser()'''. No need to use the '''as User''' |
Hey Thank you for your quick reply flutter: type 'ParseUser' is not a subtype of type 'User' please here is my User object class User extends ParseUser implements ParseCloneable { /// Looks strangely hacky but due to Flutter not using reflection, we have to static const String keyStatus = 'status'; static const String keyOrganization = 'organization'; String get status => get(keyStatus); String get about => get(keyAbout); DateTime get dob => get(keyDob); bool get online => get(keyOnline); bool get emailVerified => get(keyEmailVerified); String get firstName => get(keyFirstName); String get lastName => get(keyLastName); String get fullName => get(keyFullName); String get gender => get(keyGender); DateTime get lastseen => get(keyLastSeen); List get organization => get<List>(keyOrganization); } |
That's strange. That's pretty much the same as my project, show me an
example of where you use Parse user, i.e. how are you creating the user,
how are you calling it etc
…On Fri, Mar 22, 2019, 22:50 pastordee ***@***.***> wrote:
Hey
Thank you for your quick reply
I did as you suggested but I still get the same message
flutter: type 'ParseUser' is not a subtype of type 'User'
please here is my User object
class User extends ParseUser implements ParseCloneable {
User() : super(keyVarUsername, keyVarPassword, keyVarEmail);
User.clone() : this();
/// Looks strangely hacky but due to Flutter not using reflection, we have
to
/// mimic a clone
@OverRide <https://github.com/override>
clone(Map map) => User.clone()..fromJson(map);
static const String keyStatus = 'status';
static const String keyAbout = 'about';
static const String keyDob = 'dob';
static const String keyOnline= 'online';
static const String keyEmailVerified = 'emailVerified';
static const String keyFirstName = 'firstName';
static const String keyLastName = 'lastName';
static const String keyFullName = 'fullName';
static const String keyGender = 'gender';
static const String keyLastSeen = 'lastseen';
static const String keyOrganization = 'organization';
static const String keyBuddies = 'buddies';
static const String keyGroups = 'groups';
static const String keyWarriors = 'warriors';
String get status => get(keyStatus);
set status(String status) => set(keyStatus, status);
String get about => get(keyAbout);
set about(String about) => super.set(keyAbout, about);
DateTime get dob => get(keyDob);
set dob(DateTime dob) => set(keyDob, dob);
bool get online => get(keyOnline);
set online(bool online) => set(keyOnline, online);
bool get emailVerified => get(keyEmailVerified);
set emailVerified(bool emailVerified) => set(keyEmailVerified,
emailVerified);
String get firstName => get(keyFirstName);
set firstName(String firstName) => set(keyFirstName, firstName);
String get lastName => get(keyLastName);
set lastName(String lastName) => set(keyLastName, lastName);
String get fullName => get(keyFullName);
set fullName(String fullName) => super.set(keyFullName, fullName);
String get gender => get(keyGender);
set gender(String gender) => set(keyGender, gender);
DateTime get lastseen => get(keyLastSeen);
set lastseen(DateTime lastseen) => set(keyLastSeen, lastseen);
List get organization => get<List>(keyOrganization);
set organization(List organization) => set<List>(keyOrganization,
organization);
List get buddies => get<List>(keyBuddies);
set buddies(List buddies) => set<List>(keyBuddies, buddies);
List get groups => get<List>(keyGroups);
set groups(List groups) => set<List>(keyGroups, groups);
List get warriors => get<List>(keyWarriors);
set warriors(List warriors) => set<List>(keyWarriors, warriors);
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#137 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgn3nfRs5LMev2cpSUDEipSJfnpCELhks5vZV5BgaJpZM4cEX9X>
.
|
Any luck on this one? |
sorry no joy here, var userCurr = await ParseUser.currentUser();
this is the work around I'm using for now |
User user = _widget.prayers[position].user; not working User user = _widget.prayers[position].user as ParseUser; not working as well I still get this: 'ParseUser' is not a subtype of type 'User' |
Does your setup have the user field as a String or a pointer?
…On Tue, Apr 2, 2019, 23:21 pastordee ***@***.***> wrote:
Any luck on this one?
sorry no joy here,
var userCurr = await ParseUser.currentUser();
var queryBuilder = QueryBuilder<User>(User())
..whereEqualTo("objectId", userCurr.objectId)
..includeObject(["creator"]);
final userRe = await queryBuilder.query();
if (userRe.success){
for (var testObject in userRe.result) {
globals.user = testObject;
}
}
this is the work around I'm using for now
using the current user id to query the database and save it to a global
user or singleton
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#137 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgn3kS5bFCfUhZyjQjlhvuIxAvaiCh_ks5vc9f4gaJpZM4cEX9X>
.
|
I believe is a pointer on parse server
… On 3 Apr 2019, at 07:28, Phill Wiggins ***@***.***> wrote:
Does your setup have the user field as a String or a pointer?
On Tue, Apr 2, 2019, 23:21 pastordee ***@***.***> wrote:
> Any luck on this one?
>
> sorry no joy here,
>
> var userCurr = await ParseUser.currentUser();
>
> var queryBuilder = QueryBuilder<User>(User())
> ..whereEqualTo("objectId", userCurr.objectId)
> ..includeObject(["creator"]);
>
> final userRe = await queryBuilder.query();
> if (userRe.success){
> for (var testObject in userRe.result) {
> globals.user = testObject;
> }
> }
>
> this is the work around I'm using for now
> using the current user id to query the database and save it to a global
> user or singleton
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#137 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AHgn3kS5bFCfUhZyjQjlhvuIxAvaiCh_ks5vc9f4gaJpZM4cEX9X>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Okay, it's not ideal but there is a fix on the latest branch release/1.0.17.
Dart is struggling to recognize the saved custom object so you need to pass an instance of the customer object to the SDK. |
Thanks will try it, please also i can’t get the array from the server |
Thanks, @phillwiggins, this works for me:
|
This strategy can be evolved to:
by including this static method inside the User class:
|
And finally, to get it updated from the server, just include this static method in the User class:
and call like this:
|
v1.0.16
can anyone help trying to cast current user to custom user object like this
User user = ParseUser.currentUser() as User;
but I keep getting this error type 'Future' is not a subtype of type 'User' in type cast,
Please I'm new to Dart
Thanks
The text was updated successfully, but these errors were encountered: