class _MyHomePageState extends State<MyHomePage> {
final databaseReference = FirebaseDatabase.instance.reference();
Future<void> abs() async {
try {
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
print('beforeAnon');
await firebaseAuth.signInAnonymously();
print('AfterAnon');
} catch (e) {
print('fail');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
RaisedButton(
child: Text('anon'),
onPressed: () {
abs();
},
),
],
),
),
);
}
}
它没有在Firebase中创建任何用户,也没有进入捕获块。另外,如果我在Firebase控制台中禁用匿名登录,在执行signInAnonymously时,它也不会抛出任何异常。
在app gradle中,我添加了 implementation 'com.google.firebase:firebase-auth:19.3.1'
dependencies:
flutter:
sdk: flutter
firebase_database: ^3.1.5
firebase_auth: ^0.16.0
通过更新设备上的Google play store和Google play服务,它得到了解决。