Home > Enterprise >  how do i update the state of a text widget
how do i update the state of a text widget

Time:03-21

Hi I have been working with google sign in and i need to display the email but i can not get set state working can someone pls help! here is my code:

const Padding(
        padding: EdgeInsets.fromLTRB(9, 0, 9, 0),
        child: SignInButton(),
      ),
      Text(userEmail ?? 'email') // i need the email to update when i sign in 
    ],
  ),
 );
}
}

final _auth = FirebaseAuth.instance;
 dynamic? user;
 String? userEmail;
 String? userPhoneNumber;

 void getCurrentUserInfo() async {
   user = await _auth.currentUser!;
   userEmail = user.email;
   userPhoneNumber = user.phoneNumber;
   }

CodePudding user response:

void getCurrentUserInfo() async {
   user = await _auth.currentUser!;
   userEmail = user.email;
   userPhoneNumber = user.phoneNumber;
    setState((){})
}

assuming you are in a stateful widget. Just add setState() in getCurrentUserInfo and it should update the widget.

  • Related