Issue
How to remove the date but still keep the time?
Here is the date and time code:
ChatScreen.dart
void initState() {
super.initState();
ConversationModel objConversation = ConversationModel(
date: conversation!.date,
);
}
@override
Widget build(BuildContext context) {
...
subtitle: Text(
conversation!.date!,
style: TextStyle(color: Colors.white.withOpacity(.7), fontSize: 12),),
...
}
ConversationModel.dart
class ConversationModel {
String? date;
ConversationModel(
{
this.date,
});
ConversationModel.fromJson(Map<String, dynamic> json) {
date = json['date'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['date'] = this.date;
return data;
}
And the output:
Any solutions?
Solution
Add this to your model
String getOnlyTime(){
var time = DateTime.parse(date);
return "${time.hour}:${time.minute}";
}
Like so:
class ConversationModel {
String? date;
ConversationModel(
{
this.date,
});
ConversationModel.fromJson(Map<String, dynamic> json) {
date = json['date'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['date'] = this.date;
return data;
}
String getOnlyTime(){
var time = DateTime.parse(date!);
return "${time.hour}:${time.minute}";
}
}
Use it in your text like so:
Text(conversion!.getOnlyTime())
Answered By - Josteve
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.