You should call login function inside initState.
@override void initState() { super.initState(); login(); }