I am trying to format a String containing a date into a different Date format. I get the data from a Firestore document. When I pull the data into my UI of my flutter app I want to convert it to DateTime type so I can format it differently. EDIT I added the suggested edit.
if (trxnProvider.sellerDisclosure24a != null && trxnProvider.sellerDisclosure24a != "") {
final String? sellerDisclosure24a = trxnProvider.sellerDisclosure24a;
_dt = DateTime.parse(sellerDisclosure24a);
sellerDisclosure24aController.text = DateFormat('EE, MM-dd-yyyy').format(_dt) ?? "";
} else {
sellerDisclosure24aController.text = "";
}
However, I am getting the following error at this line
_dt = DateTime.parse(trxnProvider.sellerDisclosure24a);
The argument type 'String?' can't be assigned to the parameter type 'String'. (Documentation) 'sellerDisclosure24a' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property (trxn_provider.dart:55).
I have tried adding both "?" and "!" but I still get the error. How do I deal with this null safety issue? As you can see I am checking that data exists.