Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove date in flutter

How to remove the date but still keep the time?

Here is the date and time code:

ChatScreen.dart

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 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:

enter image description here

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())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading