Reputation: 339
dateOfEvent
value from FirebaseFirestore
but while displaying the date
fetched from the db it is not being displayed.Date of Event
fetched is 30-06-2009
and Deadline of Event
is 29-06-2009
(just the dummy value so ignore the dates)date
fetched from the firebase
but for some reason it is not being displayed. // date of event
DateTime selectedDate = DateTime.now();
TextEditingController dateController = TextEditingController();
DateTime dateOfEvent = eventDate;
Future _selectDate(context) async {
final DateTime pickedEvent = await showDatePicker(
context: context,
initialDate: eventDate,
firstDate: DateTime(1940),
lastDate: DateTime.now().subtract(Duration(days: 4380)),
helpText: 'Select Date of Event',
fieldLabelText: 'Enter date of Event',
builder: (context, child) {
return Theme(
data: ThemeData.dark().copyWith(
colorScheme: ColorScheme.dark(
primary: primaryColor, // highlighed date color
onPrimary: Colors.black, // highlighted date text color
surface: primaryColor, // header color
onSurface:
Colors.grey[800], // header text & calendar text color
),
dialogBackgroundColor: Colors.white, // calendar bg color
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: secondaryColor, // button text color
),
),
),
child: child,
);
},
);
if (pickedEvent != null && pickedEvent != dateOfEvent) {
setState(() {
dateOfEvent = pickedEvent;
print(dateOfEvent);
});
}
}
..
..
// Date of event
TextFormField(
onChanged: (value) {
setState(() {});
},
controller: dateController,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 16,
),
decoration: InputDecoration(
prefixIcon: Icon(
Icons.date_range,
color: secondaryColor,
),
labelText: 'Date of Event',
filled: true,
fillColor: formFieldFillColor,
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: secondaryColor),
borderRadius: BorderRadius.circular(15),
),
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: secondaryColor),
borderRadius: BorderRadius.circular(15),
),
),
onTap: () async {
FocusScope.of(context).requestFocus(FocusNode());
await _selectDate(context);
dateController.text =
"${DateFormat('dd-MM-yyyy').format(dateOfEvent.toLocal())}"
.split(' ')[0];
},
),
Upvotes: 0
Views: 40
Reputation: 404
probably the date is not being display because the way is being fetch from the data base, the timestamp in firebase has a range value of:
Range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z
you can find more information here
I think that if you transform that timestamp to a string for example using the function toString()
you will be able to display it in the application.
Upvotes: 1