Account account = Account(db()); // assuming db() is an instance of Client?const user = account.get('[USER-ID]');
const user_name = user.name;[SOLVED] How can i get a Username?
Votes
1
Replies
24
Participants
Unknown
Messages
25
Rank 1: Thread
Ah I'm sorry
I've been so used to the web sdk i forgot you're on flutter lol
https://appwrite.io/docs/client/account?sdk=flutter-default#accountGet
Just have a look at this!
Rank 1: Thread
ok. so i have to use this?
Future result = account.get();
result.then((response) { print(response); }).catchError((error) { print(error.response); });```
but how can i get the username?result.name
Rank 1: Thread
i dont think so, because this is an unresolved reference, but something like that (this example doesnt work)
Future result = account.get();
result.then((response) { return response["name"]; }).catchError((error) { print(error.response); });```what version of appwrite are you using?
and what's your sdk version?
Rank 1: Thread
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
appwrite: ^8.1.0```
and what's the appwrite version?
cloud or self hosted?
Rank 1: Thread
atm cloud, but in production it should be the second
can you try using async-await instead of then?
Rank 1: Thread
same error
what's the exact error?
can you show your full code snippet?
Rank 1: Thread
nvm no error,
so i have this, but this just prints instance of response
dynamic user() { Account account = Account(db()); Future result = account.get();
result.then((response) { print(response); }).catchError((error) { print(error.response); });}```Rank 1: Thread
ah i have fixed it
Rank 1: Thread
but thank you anyway!
Moderator
Can you share how did you fix it?
Rank 1: Thread
When im home yes
[SOLVED] How can i get a Username?
Rank 1: Thread
Future<String> name() async { try { var getUser = await account().get(); return getUser.name; } catch(error) { return error.toString(); } }```