我在尝试将多张图片上传到 firebase-storage 时遇到了问题,所有代码都附在下面。
我希望这个问题有任何解决方案。
变量:
String path='';
bool _showSwiper = true;
int numbers = 0;
List gallary;
图像选择器:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
child: Text("Gallery", style: TextStyle(color: Color.fromRGBO(86, 197, 150, 1))),
onPressed: () async {
List<Media> res = await ImagesPicker.pick(
count: 10,
pickType: PickType.all,
language: Language.System,
// maxSize: 500,
cropOpt: CropOption(
aspectRatio: CropAspectRatio.wh16x9,
),
);
if (res != null) {
print(res.map((e) => e.path).toList());
setState(() {
path = res[0].thumbPath;
numbers = res.map((e) => e.path).length.toInt();
gallary = res.map((e) => e.path).toList();
});
// bool status = await ImagesPicker.saveImageToAlbum(File(res[0]?.path));
// print(status);
}
Navigator.of(context, rootNavigator: true).pop();
},
)
],
)
上传功能:
Future uploadFile() async {
int i = 1;
final String fileName = DateTime.now().toString();
for (var img in gallary) {
setState(() {
val = i / gallary.length;
});
print(img.path);
Reference ref = FirebaseStorage.instance
.ref()
.child('images/${Path.basename(img.path)}');
UploadTask uploadTask = ref.putFile(img);
await uploadTask;
//
// FirebaseStorage storage = FirebaseStorage.instance;
//
// Reference ref = FirebaseStorage.instance.ref('/images');
}}
我在尝试将多张图片上传到 firebase-storage 时遇到了问题,所有代码都附在下面。
我希望这个问题有任何解决方案。