Get selected image path through Asset in flutter?

340

FlutterAbsolutePath is not supported to null safety

I used button click event to get the image Path from Asset

floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),

        onPressed: () async {

              final key = DateTime.now().toString();
              File file = await getImageFileFromAssets(images[1]);

              for(int i=0;i<images.length;i++)
                {
                  print('# file path is ${file.path} #');
                }

        },
      ),

The method which is converting Asset to the image path

Future<File> getImageFileFromAssets(Asset asset) async {
    final byteData = await asset.getByteData();

    final tempFile =
    File("${(await getTemporaryDirectory()).path}/${asset.name}");
    final file = await tempFile.writeAsBytes(
      byteData.buffer
          .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes),);

    return file;
  }
Share:
340
Prasath
Author by

Prasath

தோல்வி நிலையென நினைத்தால் மனிதன் வாழ்வை நினைக்கலாமா &gt; Parunthaguthu Oor Kuruvi, Adangathathu En Piravi, Adanga Pala Madanga &gt; Varum, Thaduththa Adthu Udachchi Varuven, Ippo Vanthu Mothu Da, Kitta &gt; Vanthu Paru Da, Kattaruntha Kala, Nenju Mela Era Pothu Da, Thimiru Da &gt; Thimira Thimira, Nimiru Da Nilama Nilama, Unaru Da Payanam Payanam, &gt; Thodarum Da, Tha Ippo Vanthu Mothu Da, Kitta Vanthu Paru Da Paru Da, Porus ---- My Rule. Don't ask me, What is the Update or What is the Progress, However, I will be give you on correct time

Updated on December 31, 2022

Comments

  • Prasath
    Prasath over 1 year

    I used multi_image_picker: to select images from the internal storage. This library returns List of Asset, but I want as an image path, I used FlutterAbsolutePath

    var path = await FlutterAbsolutePath.getAbsolutePath(resultList[i].identifier);
    

    but this is not supported to null safety, How can I get an image path using the similar library?