AuthService.dart
static Future<void> login(
BuildContext context, String email, String password) {
try{
UserCredential userCredential = await FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password);
}catch(e){
print(e);
}
Future <void> signOut() async {
await FirebaseAuth.instance.signOut();
}
}
登录页面dart
ElevatedButton(
onPressed: () {
setState(() async{
if (_loginFormKey.currentState!.validate()) {
_loginFormKey.currentState!.save();
await AuthService.login(context, email!, password!);
}
});
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.resolveWith(
(states) => Colours.blk),
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
))),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Log in"
),
],
),
),
主页.dart
IconButton(
onPressed: () {
setState(() {
Provider.of<AuthService>(context, listen: false)
.signOut();
});
},
icon: const Icon(
IC.MaterialIcons.logout,
)),
每当我在成功登录后使用注销时,当前用户id都是持久的,这使得除非重新启动网站,否则无法使用不同的凭据登录
你能试着像这个一样注销吗
Future<void> _signOut() async {
await FirebaseAuth.instance.signOut();
}