0

I want to convert following

Future<UserDetl> f = AppDatabase().userById('55e62a90-273c-11ea-9441-f75d5cd0114b');

into List<UserDetl> lstUser

class UserDetl {
  String userId;
  String userName;
  String userPlace;
  String userUrl;

  UserDetl(this.userId,this.userName, this.userPlace, this.userUrl);

}

and I wanna get username from the list

String user = lstUser[0].userName;
Ashique bzq
  • 541
  • 2
  • 9
  • 21
  • Did you tried https://stackoverflow.com/questions/55011075/return-a-list-from-a-future-in-flutter – Pankaj Kumar Dec 26 '19 at 09:00
  • that one using FutureBuilder method, and that method is only applicable to Future> – Ashique bzq Dec 26 '19 at 09:02
  • Does this answer your question? [Getting values from Future instances](https://stackoverflow.com/questions/46579358/getting-values-from-future-instances) – easeccy Dec 26 '19 at 09:16

3 Answers3

0

try this !

getUser() async {

UserDetl tmp = await  AppDatabase().userById('55e62a90-273c-11ea-9441-f75d5cd0114b');

if(tmp!=null)
 setState((){
    UserDetl u = v;
});
}
Naveen Avidi
  • 3,004
  • 1
  • 11
  • 23
0

You simply have to build a list with your result:

Future<UserDetl> f = AppDatabase().userById('55e62a90-273c-11ea-9441-f75d5cd0114b');
UserDetl user = await f;
List<UserDetl> lstUser = [user];
Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132
0
Future<UserDetl> f = //get your Futuredata
UserDetl user = await f;
List<UserDetl> lstUser = [user];//add in list

//you also can get it from list like:

UserDetl user = lstUser[0];
Jaydeep chatrola
  • 2,423
  • 11
  • 17