Und*_*doX 4 android dart flutter
在我的应用程序正常之前,我尝试使用图像路径上传图像。当我尝试添加 import 'package: path / path.dart'; 和 basename (image.path) 为了上传我的图像,我的对话框警报中出现了一个新错误。上下文中的更多细节:上下文。这是我的代码:
import 'package:path/path.dart';
Future uploadFile() async {
final FirebaseUser user = await FirebaseAuth.instance.currentUser();
final userId = user.uid;
_imageList.forEach((_image) {
final StorageReference firebaseStorageRef = FirebaseStorage.instance
.ref()
.child('category')
.child('food')
.child('images')
.child(username)
.child(basename(_image.path));
final StorageUploadTask task = firebaseStorageRef.putFile(_image);
return task;
});
}
Run Code Online (Sandbox Code Playgroud)
以及出现错误的以下代码:
Future<void> alertSuccess() async {
return showDialog<void>(
/*this error*/
context: context,
/*------------*/
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Success'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(
'You success save data.'),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('OK'),
onPressed: () {
Navigator.pop(context);
Navigator.pushReplacement(
context,
new MaterialPageRoute(
builder: (context) => PublicService()));
},
),
],
);
},
);
}
Run Code Online (Sandbox Code Playgroud)
path.dart 覆盖框架的全局 Context 变量。:-( 因此,在路径包开发人员解决此问题之前,评论中 Günter Zöchbauer 的解决方案是有效的。使用包的别名并通过别名访问它。如果您像我一样有其他称为“路径”的变量,您需要重命名它们,例如:
导入 'package:path/path.dart' 作为路径;
然后例如使用
final imgPath = path.join(
(await _localPath),
'${DateTime.now()}.png',
);
Run Code Online (Sandbox Code Playgroud)
代替
final path = join(
(await _localPath),
'${DateTime.now()}.png',
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2254 次 |
| 最近记录: |