当我查看基本名称的官方文档时,我遇到了基本名称的问题,在我看来一切都“正常”。但它仍然显示basename上的错误。感谢您的时间!
错误 basename 错误:表达式的计算结果不是函数,因此无法调用局部变量“basename”在声明之前无法引用。
代码片段
Future uploadImageToFirebase(BuildContext context) async {
String basename = basename(_imageFile.path);
StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child('uploads/$basename');
StorageUploadTask uploadTask = firebaseStorageRef.putFile(_imageFile);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
taskSnapshot.ref.getDownloadURL().then(
(value) => print("Done: $value"),
);
}
Run Code Online (Sandbox Code Playgroud)
上下文部分代码片段
void addToFb() async {
final User user = FirebaseAuth.instance.currentUser;
...
dbRef.add({
...
}).then((res) {
isLoading = false;
Navigator.pushReplacement(
context, <--- HERE I GOT AND ERROR
MaterialPageRoute(builder: (context) => Home(uid: widget.uid)),
);
}).catchError(
(err) {
showDialog(
context: context, <--- HERE I GOT AND …Run Code Online (Sandbox Code Playgroud)