List of files in flutter

前端 未结 2 920
清歌不尽
清歌不尽 2021-01-02 16:20

I have images and I want to load them to my appplication. my_app/lib/... - here my source files my_app/assets/images/... - here my images

I need to get list of files

2条回答
  •  梦谈多话
    2021-01-02 16:28

    When you add files to your assets, it means that you already know their paths. Store all the images paths in a list and access them whenever you need.

    For example if you have 3 images in

    your_app/assets/images/image1.jpg
    your_app/assets/images/image2.jpg
    your_app/assets/images/image3.jpg

    create a list and store all of them like:

    List imagePaths = ['assets/images/image1.jpg', 'assets/images/image2.jpg', 'assets/images/image3.jpg'];
    

    and for example if you want to access your first image, use

    AssetImage(imagePaths[0])

提交回复
热议问题