Back

[SOLVED] How can i get a Username?

  • 1
  • Users
  • Flutter
safwan
11 Aug, 2023, 12:42
TypeScript
Account account = Account(db());  // assuming db() is an instance of Client?
const user = account.get('[USER-ID]');

const user_name = user.name;
TL;DR
User is trying to retrieve the username using the `get()` method from the `Account` class in the Appwrite SDK. Initially, the code only printed `__instance of response__`. They are using `then` and `catchError` for handling the response and error, respectively. Another user suggests using `async-await` instead of `then`. User also mentions that they are on Flutter and are using Appwrite version 8.1.0. The solution provided is to use `async-await` and assign the result of `account.get()` to a variable. Then, access the `name` property of the response to
plushteddy
11 Aug, 2023, 12:45
safwan
11 Aug, 2023, 12:49

Ah I'm sorry

safwan
11 Aug, 2023, 12:49

I've been so used to the web sdk i forgot you're on flutter lol

safwan
11 Aug, 2023, 12:49
plushteddy
11 Aug, 2023, 12:52

ok. so i have to use this?

TypeScript
      Future result = account.get();

      result.then((response) {
        print(response);
      }).catchError((error) {
        print(error.response);
      });```

but how can i get the username?
safwan
11 Aug, 2023, 12:54

result.name

plushteddy
11 Aug, 2023, 12:57

i dont think so, because this is an unresolved reference, but something like that (this example doesnt work)

TypeScript
Future result = account.get();

  result.then((response) {
    return response["name"];
  }).catchError((error) {
    print(error.response);
  });```
safwan
11 Aug, 2023, 12:58

what version of appwrite are you using?

safwan
11 Aug, 2023, 12:58

and what's your sdk version?

plushteddy
11 Aug, 2023, 12:59
TypeScript
dependencies:
  flutter:
    sdk: flutter


  cupertino_icons: ^1.0.2
  appwrite: ^8.1.0```
safwan
11 Aug, 2023, 12:59

and what's the appwrite version?

safwan
11 Aug, 2023, 13:00

cloud or self hosted?

plushteddy
11 Aug, 2023, 13:00

atm cloud, but in production it should be the second

safwan
11 Aug, 2023, 13:01

can you try using async-await instead of then?

plushteddy
11 Aug, 2023, 13:05

same error

safwan
11 Aug, 2023, 13:05

what's the exact error?

safwan
11 Aug, 2023, 13:05

can you show your full code snippet?

plushteddy
11 Aug, 2023, 13:24

nvm no error,

so i have this, but this just prints instance of response

TypeScript
dynamic user() {
  Account account = Account(db());
  Future result = account.get();

  result.then((response) {
    print(response);
  }).catchError((error) {
    print(error.response);
  });
}```
plushteddy
11 Aug, 2023, 13:25

ah i have fixed it

plushteddy
11 Aug, 2023, 13:25

but thank you anyway!

Guille
12 Aug, 2023, 13:14

Can you share how did you fix it?

plushteddy
12 Aug, 2023, 13:57

When im home yes

Drake
12 Aug, 2023, 16:45

[SOLVED] How can i get a Username?

plushteddy
13 Aug, 2023, 11:29
TypeScript
  Future<String> name() async {
    try {
      var getUser = await account().get();
      return getUser.name;
    } catch(error) {
      return error.toString();
    }
  }```
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more