1

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.

1 Answer 1

2

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);
 });  
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.