In Flutter How to get image path after selecting images using Multi Image Picker?

后端 未结 4 1402
执笔经年
执笔经年 2021-01-18 18:13

I want to get an image path from selected multiple images, I\'m using this link to select multiple images but I got assets, I want paths from selected multiple images becaus

4条回答
  •  一生所求
    2021-01-18 18:58

    You can also select multiple images using file_picker: ^1.5.0+2 library and easy to get path of selected images

    Future getFilePath() async {
    try {
      files = await FilePicker.getMultiFile();
      if (files == '') {
        return 0;
      }
      else
      {
        setState(() {
          this._filePath = files;
          return 1;
        });
      }
    
    } on PlatformException catch (e) {
      print("Error while picking the file: " + e.toString());
    }
    

    }

    show selected images by using ListView Builder like this

                   ListView.builder(
                  scrollDirection: Axis.horizontal,
                  itemCount: _filePath.length,
                  itemBuilder: (context,c)
                  {
    
                    return Card(
                      child: Image.file(_filePath[c],
                        fit: BoxFit.fill,
                        width: 400,
                        height: 400,
    
                      ),
                    );
                  }
              ),
    

提交回复
热议问题