不能在flutter中使用firebase集成



在将库更新到最新版本后,我将在flutter应用程序中使用firebase。以下是以前使用的代码,但现在我面临错误

代码

void main() {
FirebaseFirestore.instance.settings(timestampsInSnapshotsEnabled: true).then((_) {
print("Timestamps enabled in snapshotsn");
}, onError: (_) {
print("Error enabling timestamps in snapshotsn");
});
runApp(MyApp());
}

错误

error: The expression doesn't evaluate to a function, so it can't be invoked.

当我实现上面的代码时,我得到了错误,请帮助我解决这个

下面是一个应该修复它的代码。

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}

您需要在运行App(MyApp(((之前初始化Firebase实例;

void main() async{
WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp();
//Before running App During load time initialize firebase instance.
runApp(MyApp());
}

最新更新