Hi everyone,
I'm currently facing an issue with converting a DateTime stamp received from the backend into a more formatted string in Flutter. I'm aiming to display the date as "June 10th, 2024".
Hi everyone,
I'm currently facing an issue with converting a DateTime stamp received from the backend into a more formatted string in Flutter. I'm aiming to display the date as "June 10th, 2024".
Here's what I've tried:
I attempted to create a custom function to format the DateTime.
I encountered a type error: "String is not a subtype of DateTime".
It seems like there's a mismatch in data types somewhere in my code. Could anyone help me troubleshoot this or provide a snippet that could handle this conversion correctly?import 'dart:convert';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import '/flutter_flow/lat_lng.dart';
import '/flutter_flow/place.dart';
import '/flutter_flow/uploaded_file.dart';
import '/flutter_flow/custom_functions.dart';
import '/backend/backend.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import '/auth/custom_auth/auth_util.dart';
DateTime? convertDate(dynamic date) {
/// MODIFY CODE ONLY BELOW THIS LINE
// convert date timestamp into yMMMd
if (date == null) return null;
final format = DateFormat.yMMMd();
return format.format(date);
/// MODIFY CODE ONLY ABOVE THIS LINE
}