Android 在颤振中使用图像列表多次上传图像

Android 在颤振中使用图像列表多次上传图像,android,firebase,dart,flutter,firebase-storage,Android,Firebase,Dart,Flutter,Firebase Storage,我是新手。我试着用flatter制作一个上传图片的应用程序。我已成功地从图像选择器中拾取了一些图像,但当我尝试将数据写入firebase存储时,仅成功上载了一个图像。这是我的代码: List<File> _imageList = []; File _image; Future uploadFile() async { final FirebaseUser user = await FirebaseAuth.instance.currentUser(); fina

我是新手。我试着用flatter制作一个上传图片的应用程序。我已成功地从图像选择器中拾取了一些图像,但当我尝试将数据写入firebase存储时,仅成功上载了一个图像。这是我的代码:

List<File> _imageList = [];
File _image;

  Future uploadFile() async {
    final FirebaseUser user = await FirebaseAuth.instance.currentUser();
    final userId = user.uid;
    final StorageReference firebaseStorageRef =
        FirebaseStorage.instance.ref().child(userId).child('images');
    final StorageUploadTask task = firebaseStorageRef.putFile(_image);
    return task;
  }
List_imageList=[];
文件图像;
未来上传文件()异步{
final FirebaseUser user=等待FirebaseAuth.instance.currentUser();
最终用户ID=user.uid;
最终存储参考firebaseStorageRef=
FirebaseStorage.instance.ref().child(userId.child('images');
最终StorageUploadTask任务=firebaseStorageRef.putFile(_image);
返回任务;
}
这是我选择和显示图像的代码

 Future getImageFromGallery() async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);
    setState(() {
      _image = image;
      _imageList.add(_image);
    });
  }

List<Widget> builtImageDisplay() {
    return [
      Padding(
        padding: const EdgeInsets.all(8.0),
        child: new Center(
          child: Padding(
            padding: const EdgeInsets.all(15.0),
            child: _imageList.length == 0
                ? new Image.asset('assets/images/format.jpg')
                : GridView.count(
                    shrinkWrap: true,
                    primary: false,
                    crossAxisCount: 4,
                    mainAxisSpacing: 5.0,
                    crossAxisSpacing: 5.0,
                    children: _imageList.map((File file) {
                      return GestureDetector(
                        onTap: () {},
                        child: new GridTile(
                          child: new Image.file(
                            file,
                            fit: BoxFit.cover,
                          ),
                        ),
                      );
                    }).toList(),
                  ),
          ),
        ),
      )
    ];
  }
Future getImageFromGallery()异步{
var image=wait ImagePicker.pickImage(源:ImageSource.gallery);
设置状态(){
_图像=图像;
_imageList.add(_image);
});
}
列表内置图像显示(){
返回[
填充物(
填充:常数边集全部(8.0),
孩子:新中心(
孩子:填充(
填充:常数边集全部(15.0),
子项:_imageList.length==0
?新建Image.asset('assets/images/format.jpg')
:GridView.count(
收缩膜:对,
主要:错误,
交叉轴计数:4,
主轴间距:5.0,
交叉轴间距:5.0,
子项:_imageList.map((文件){
返回手势检测器(
onTap:(){},
孩子:新格子(
子:新建Image.file(
文件
适合:BoxFit.cover,
),
),
);
}).toList(),
),
),
),
)
];
}

简单的
功能
上传多个图像文件

import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

  Future<Null> _uploadImages() async {
    _imageList.forEach((f) {
      final StorageReference _ref = storageImageRef.child(basename(f.path));
      final StorageUploadTask uploadTask = _ref.putFile(f);
    });
import'package:path/path.dart';
导入“package:path_provider/path_provider.dart”;
Future\u uploadImages()异步{
_imageList.forEach((f){
最终StorageReference_ref=storageImageRef.child(basename(f.path));
final StorageUploadTask uploadTask=\u ref.putFile(f);
});

简单的
功能
上传多个图像文件

import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

  Future<Null> _uploadImages() async {
    _imageList.forEach((f) {
      final StorageReference _ref = storageImageRef.child(basename(f.path));
      final StorageUploadTask uploadTask = _ref.putFile(f);
    });
import'package:path/path.dart';
导入“package:path_provider/path_provider.dart”;
Future\u uploadImages()异步{
_imageList.forEach((f){
最终StorageReference_ref=storageImageRef.child(basename(f.path));
final StorageUploadTask uploadTask=\u ref.putFile(f);
});

anmol.mahjhail收到了!谢谢..你帮我保存一天!^ ^我怎样才能获得所有下载URL?anmol.mahjhail收到了!谢谢..你帮我保存一天!^ ^ ^我怎样才能获得所有下载URL?对于迟到的访问者,这里是一个上传图片列表和下载URL的答案