Reputation: 447
I create a button to test the database. it returns a set of data. While i did in initState function, what i get is null.
@override
void initState() {
db.queryData('username').then((val) {
_userAuthData = val;
});
super.initState();
print(_userAuthData);
}```
** both async/await and future.then() works the same in button on press function.
Upvotes: 1
Views: 318
Reputation: 1180
you can execute async function on init method by using future
@override
void initState() {
super.initState();
Future.delayed(Duration.zero,()async{
final _userAuthData=await db.queryData('username');
print(_userAuthData);
});
});
Upvotes: 2