[英]The method 'configure' isn't defined for the type 'FirebaseApp'
I'm using firebase Authentication for user login but getting this error message for FirebaseApp Configure Method.我正在使用 firebase 身份验证进行用户登录,但收到 FirebaseApp 配置方法的此错误消息。
below is my code.下面是我的代码。
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import '../Questions.dart';
class Tasks extends StatefulWidget {
Tasks({this.uid: ""});
final String uid;
@override
TasksState createState() => TasksState(uid);
}
class TasksState extends State<Tasks> {
var now = DateTime.now();
bool timeUp = true;
TasksState(this.userId);
Map<String, dynamic> identifiers = Map.from({
"answered": false,
"value": false,
"notDone1": true,
"notDone2": true,
"defNumber": -1,
"hour": null
});
FirebaseAuth auth = FirebaseAuth.instance;
String userId;
DocumentReference ansRef;
Future<void> configure() async {
final FirebaseApp app = await FirebaseApp.configure(
name: 'companionbeta',
options: const FirebaseOptions(
googleAppID: '*******************************',
apiKey: '********************************',
projectID: '*******************'
));
final FirebaseFirestore firestore = Firestore.instance();
await firestore.settings(timestampsInSnapshotsEnabled: true);
}
bool isDepressed(DocumentSnapshot document) {
document.data.putIfAbsent("q1", document["defNumber"]);
if (document["q1"] < 3) return true;
return false;
}
@override
void initState() {
configure();
ansRef = Firestore.instance.collection("answers").document(userId);
addData();
super.initState();
}
void updateTime(DocumentSnapshot document) async {
if (document["hour"] == null)
await document.reference.updateData({"hour": now.hour});
assert(now.hour != null);
if (document["hour"] < 24) {
setState(() {
timeUp = true;
});
await document.reference.updateData({"hour": document["hour"] + 24});
}
}
void addData() async {
ansRef.get().then((DocumentSnapshot ds) {
ds.data.addAll(identifiers);
updateTime(ds);
isDepressed(ds);
});
}
@override
Widget build(BuildContext context) {
return Material(
child: StreamBuilder(
stream: Firestore.instance.collection("answers").snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Text("Loading..");
DocumentSnapshot doc = snapshot.data.documents[0];
Map<String, bool> check = Map.from({
"answered": (doc["answered"] == null) ? false : true,
"notDone1": (doc["notDone1"] == null) ? false : true,
"notDone2": (doc["notDone2"] == null) ? false : true,
"q1": (doc["q1"] == null) ? false : true,
});
return builder(context, doc, check);
}));
}
Widget builder(BuildContext context, DocumentSnapshot document,
Map<String, bool> check) {
return Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
(check["answered"] && timeUp && !document["answered"])
? askQuestion(document)
: Container(),
Flexible(
child: Card(
child: ListView(
children: <Widget>[
(check["notDone1"] &&
check["q1"] &&
isDepressed(document) &&
document["notDone1"])
? ListTile(
contentPadding: EdgeInsets.all(10.0),
leading: Icon(Icons.people),
title: Text("Meet more people"),
subtitle: Text("uno dos tres"),
trailing: Checkbox(
value: false,
onChanged: (value) {
setState(() {
if (value)
document.reference.updateData({"notDone1": false});
});
},
),
)
: Container(),
(check["notDone2"] &&
check["q1"] &&
isDepressed(document) &&
document["notDone2"])
? ListTile(
contentPadding: EdgeInsets.symmetric(horizontal: 10.0),
leading: Icon(Icons.library_music),
title: Text("Listen to tunes"),
subtitle: Text("uno dos tres"),
trailing: Checkbox(
value: document["value"],
onChanged: (value) {
setState(() {
if (value)
document.reference.updateData({"notDone2": false});
});
},
),
)
: Container(),
(check["q1"] &&
check["notDone1"] &&
isDepressed(document) &&
!document["notDone1"])
? Card(
child: Expanded(
child: Text("Yay! We are happy today"),
))
: Container()
],
),
elevation: 2.0,
margin: EdgeInsets.symmetric(horizontal: 12.0, vertical: 6.0),
))
]);
}
Widget askQuestion(DocumentSnapshot document) {
return Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const ListTile(
leading: Icon(Icons.question_answer),
title: Text('Ready to answer a few questions?'),
subtitle: Text('It will only take a minute'),
),
ButtonTheme.bar(
// make buttons use the appropriate styles for cards
child: ButtonBar(
children: <Widget>[
FlatButton(
child: const Text('Yes!'),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => Questions(document)));
},
),
FlatButton(
child: const Text('Not now'),
onPressed: () {
setState(() {
document.reference.updateData({"answered": true});
});
},
),
],
),
),
],
),
elevation: 2.0,
margin: EdgeInsets.all(12.0),
);
}
}
for privacy issue's i'm removed googleID, appkey, and projectId, so ignore that.对于隐私问题,我删除了 googleID、appkey 和 projectId,所以忽略它。
error message.错误信息。
The method 'configure' isn't defined for the type 'FirebaseApp'.没有为“FirebaseApp”类型定义“配置”方法。 Try correcting the name to the name of an existing method, or defining a method named 'configure'.
尝试将名称更正为现有方法的名称,或定义名为“configure”的方法。
FirebaseApp
does not have a method called configure
, you need to use initializeApp
: FirebaseApp
没有名为configure
的方法,您需要使用initializeApp
:
final FirebaseApp app = await FirebaseApp.initializeApp(
name: 'companionbeta',
options: const FirebaseOptions(
googleAppID: '*******************************',
apiKey: '********************************',
projectID: '*******************'
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.