在 flutter 中访问 firebase 用户的当前 uid 时出错
Error while accessing current uid of firebase user in flutter
我想用flutter获取当前用户的uid
我试过跟随但 returns 出错
final FirebaseAuth auth = FirebaseAuth.instance;
void inputData() {
final User user = auth.currentUser;
final uid = user.uid;
print(uid);
// here you write the codes to input the data into firestore
}
错误:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
你必须打电话给 Firebase.initializeApp()
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
Firebase 现已更新,需要您在使用任何 Firebase 产品之前初始化 Firebase。
还要确保你的 pubspec.yaml 文件有 firebase_core:
dependencies:
flutter:
sdk: flutter
firebase_core : ^0.5.0
并且主要在main.dart
的main函数中初始化Firebase
Firebase.initializeApp();
我想用flutter获取当前用户的uid
我试过跟随但 returns 出错
final FirebaseAuth auth = FirebaseAuth.instance;
void inputData() {
final User user = auth.currentUser;
final uid = user.uid;
print(uid);
// here you write the codes to input the data into firestore
}
错误:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
你必须打电话给 Firebase.initializeApp()
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
Firebase 现已更新,需要您在使用任何 Firebase 产品之前初始化 Firebase。 还要确保你的 pubspec.yaml 文件有 firebase_core:
dependencies:
flutter:
sdk: flutter
firebase_core : ^0.5.0
并且主要在main.dart
的main函数中初始化FirebaseFirebase.initializeApp();