我从firestore中读取数据,并将其用于电子邮件的url启动器。但是我在提示打开电子邮件时得到的值是NULL。但是它不会提示任何错误。
我列出的将数据设置为var的代码。
one_to_many
用于从Firestore获取数据以获取用户详细信息和发件人电子邮件地址的代码
var userName, userAdd, userAge, userResult, uniEmail;
void emailDetail() async{
Widget build(BuildContext context) {
return new StreamBuilder(
stream: UniQuery().getUserDetail(),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData)
return new Text('Loading..... Please wait');
var userDocument = snapshot.data;
userName = userDocument['name'];
userAge = userDocument['age'];
userAdd = userDocument['address'];
userResult= userDocument['result'];
return new Text('Success read user data');
}
);
}
}
void emailAddress() async{
Widget build(BuildContext context) {
return new StreamBuilder(
stream: UniQuery().getUniBasedSelectedUni(),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData)
return new Text('Loading..... Please wait');
var userDocument = snapshot.data;
uniEmail = userDocument['email'];
return new Text('Success read university email');
}
);
}
}
void sendEmail() async {
emailDetail();
emailAddress();
var url = 'mailto:$uniEmail?subject= University Application'
+'&body= Name: $userName \nAge: $userAge \nAddress: $userAdd'
+'\nResult: $userResult';
if (await canLaunch(url)) {
await launch(url);
}
else {
throw 'Could not launch $url';
}
}
我在这里称它为sendEmail
Future<String> getCurrentUser() async{
final FirebaseUser user = await FirebaseAuth.instance.currentUser();
final String uID = user.uid.toString();
return uID;
}
setUserDetail() async{
userID = await getCurrentUser();
}
getUserDetail(){
setUserDetail();
return dbReference.collection('User')
.document(userID)
.snapshots();
}
getUniBasedSelectedUni(){
return dbReference.collection('University')
.where('name', isEqualTo: selectedUni)
.snapshots();
}