6

this is my submit function every things is fine but _imagesAssets.forEach not run and _images list will be null.any idea will be greate

if (_formKey.currentState.validate()) {
      _images.clear();
      _imagesAssets.forEach((element) async {
        _images.add(await getImageFileFromAssets(element));
      });
      PersianDateTime persianDate1 =
          PersianDateTime(jalaaliDateTime: dateTextController.text);
      persianDate1.toGregorian();

      _preferences = await SharedPreferences.getInstance();
      String _apiToken = _preferences.getString('apiToken');

      TransactionAddDto transactionAddDto = new TransactionAddDto(
        isCharity: _isCharity,
        payDate: persianDate1.datetime.toString().replaceFirst(" ", "T"),
        imageArray: _images,
        apiToken: _apiToken,
        userId: _selectedUser,
        payVal: _transactionVal.toDouble(),
      );
      _transactionBloc.add(
        new AddTransactionEvent(transactionAddDto),
      );
    }
amin jamali
  • 360
  • 1
  • 3
  • 16

1 Answers1

6

Change this code

_imagesAssets.forEach((element) async {
  _images.add(await getImageFileFromAssets(element));
});

Into this

for (var imageAsset in _imagesAssets) {
  _images.add(await getImageFileFromAssets(imageAsset));
}

Let me know if it works.

Raiyan
  • 388
  • 2
  • 11