Issue
Map<String, dynamic> mapOfObjects;
dates = mapOfObjects['dates'] as List<Timestamp>;
mapOfObjects looks like this:
{requiredCompletions: 0, totalCompletions: 0, incentive: [{rewardAmt: 0, rewardId: }], habitType: 1, id: , habitNotifications: false, dates: [Timestamp(seconds=1618903800, nanoseconds=0)], habitDescription: }
I am running this under a FutureBuilder that is fetching from Firebase, and it is getting hung up on the dates. I can specify the index by doing the following:
date = mapOfObjects['dates'][0] as Timestamp;
and it works perfectly fine. Why isn’t the as
casting working?
Solution
dates = List<Timestamp>.from(mapOfObjects['dates'] as List);
Answered By – Sarbagya Dhaubanjar
Answer Checked By – Marie Seifert (FlutterFixes Admin)