How to display date and time in text widget of flutter?
522
the toDate() method is available in the string_validator package. I think you should use the default DateTime.parse() and use it as:
var parsedDate = DateTime.parse(data['createdAt']);
Then run it through the DateFormat as:
DateFormat('dd/MM/yyyy').format(parsedDate))
Author by
Tushar Rai
Updated on November 26, 2022Comments
-
Tushar Rai over 1 year
I am trying to display date and time in text widget of flutter with the help of
import 'package:intl/intl.dart';
package, but its throwing and error.The following NoSuchMethodError was thrown building:
The method 'toDate' was called on null. Receiver: null Tried calling: toDate()
Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Text('Order Date: ${DateFormat('dd/MM/yyyy').format(data['createdAt'].toDate())}'), Text('Order Time: ${DateFormat('hh:mm a').format(data['createdAt'].toDate())}'), ],),
-
lava about 2 yearscould you provide your time and date
-
markhorrocks about 2 yearsHe doesn't have a date, it's null. I think the question is how to display a null date?
-
-
Tushar Rai about 2 yearsI have tried it already with this. it is throwing an error type 'Timestamp' is not a subtype of type 'String'