my code is below. I want it to be type-recognized as a datetime type at compile time.
var myList = [{
'message': 'foo',
'time': DateTime.now()
}];
DateTime.now().difference(myList[0]['time']);
and it has error of The argument type 'Object?' can't be assigned to the parameter type 'DateTime'.
how can i fix this?
CodePudding user response:
You need to add a type cast for this with the as
keyword:
DateTime.now().difference(myList[0]['time'] as DateTime)