方法“收集”为Firebasestorage类型定义的IS不定义
试图将数据存储在Firestore中,我会遇到错误。另一个问题是在Android Studio(Pixel 5)中使用我的仿真器,甚至使用我的所有4个连接设备。我可以跑步,但他们什么都没有表现出来。 Flutter医生发现没有问题。请帮助我tryna做一个我看不到的应用程序,而是利用我对它的外观的想象,这不是正确的方法。
import 'package:firebase_storage/firebase_storage.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:swift_mobile/constants.dart';
import 'user_model.dart' as model;
class AuthController extends GetxController{
static AuthController instance = Get.find();
late Rx<File?> _pickedImage;
File? get profilePicture => _pickedImage.value;
void pickAnImage() async {
final pickedImage = await ImagePicker().pickImage(source: ImageSource.gallery);
if(pickedImage!=null) {
Get.snackbar('Profile Picture', 'You\'re good to go!');
}
_pickedImage = Rx<File?>(File(pickedImage!.path));
}
Future<String> _uploadToStorage(File image) async {
Reference ref = firebaseStorage
.ref().child('profilePictures')
.child(firebaseAuth
.currentUser!.uid
);
UploadTask uploadTusk = ref.putFile(image);
TaskSnapshot snap = await uploadTusk;
String downloadUrl = await snap.ref.getDownloadURL();
return downloadUrl;
}
void registerUser(String username, String email, String password, File? image) async {
try{
if(username.isNotEmpty &&
email.isNotEmpty &&
password.isNotEmpty &&
image!=null) {
UserCredential cred = await firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
String downloadUrl = await _uploadToStorage(image);
model.User user = model.User(name: username, email: email, uid: cred.user!.uid, profilePic: downloadUrl);
await firestore.collection('user').doc(cred.user!.uid).set(user.toJson());
} else {
Get.snackbar(
'Error creating account',
'Please enter all fields',
);
}
} catch(e) {
Get.snackbar(
'Error creating account',
e.toString());
}
}
} ```
I'm getting an error trying to store data in firestore. Another issue is using my emulator in android studio ( pixel 5 ) or even all my 4 connected devices. I can run but they all show nothing. Flutter doctor finds no issues. Please help I'm tryna make an application I can't see but rather use my imagination of how it'd looks and this is not the correct way.
import 'package:firebase_storage/firebase_storage.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:swift_mobile/constants.dart';
import 'user_model.dart' as model;
class AuthController extends GetxController{
static AuthController instance = Get.find();
late Rx<File?> _pickedImage;
File? get profilePicture => _pickedImage.value;
void pickAnImage() async {
final pickedImage = await ImagePicker().pickImage(source: ImageSource.gallery);
if(pickedImage!=null) {
Get.snackbar('Profile Picture', 'You\'re good to go!');
}
_pickedImage = Rx<File?>(File(pickedImage!.path));
}
Future<String> _uploadToStorage(File image) async {
Reference ref = firebaseStorage
.ref().child('profilePictures')
.child(firebaseAuth
.currentUser!.uid
);
UploadTask uploadTusk = ref.putFile(image);
TaskSnapshot snap = await uploadTusk;
String downloadUrl = await snap.ref.getDownloadURL();
return downloadUrl;
}
void registerUser(String username, String email, String password, File? image) async {
try{
if(username.isNotEmpty &&
email.isNotEmpty &&
password.isNotEmpty &&
image!=null) {
UserCredential cred = await firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
String downloadUrl = await _uploadToStorage(image);
model.User user = model.User(name: username, email: email, uid: cred.user!.uid, profilePic: downloadUrl);
await firestore.collection('user').doc(cred.user!.uid).set(user.toJson());
} else {
Get.snackbar(
'Error creating account',
'Please enter all fields',
);
}
} catch(e) {
Get.snackbar(
'Error creating account',
e.toString());
}
}
} ```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
firebase.Collection
用:进口firestore。这与存储是不同的。
Replace
firebase.collection
with :And import Firestore. It's a different thing from storage.