From 139f1bc5cd3169bd332d99abd6c3a76efe410024 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sat, 16 Feb 2019 19:57:20 +0100 Subject: [PATCH] JournalList: Show the fileName if the note has an invalid date --- lib/note.dart | 5 ++++ lib/widgets/journal_list.dart | 45 +++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/note.dart b/lib/note.dart index def5bfc6..99100b4c 100644 --- a/lib/note.dart +++ b/lib/note.dart @@ -16,6 +16,11 @@ class Note implements Comparable { } } + bool hasValidDate() { + // Arbitrary number, when we set the year = 0, it becomes 1, somehow + return created.year > 10; + } + factory Note.fromJson(Map json) { String filePath = ""; if (json.containsKey("filePath")) { diff --git a/lib/widgets/journal_list.dart b/lib/widgets/journal_list.dart index 393d0b82..b67d4b3d 100644 --- a/lib/widgets/journal_list.dart +++ b/lib/widgets/journal_list.dart @@ -4,6 +4,7 @@ import 'package:intl/intl.dart'; import 'package:journal/note.dart'; import 'package:journal/state_container.dart'; import 'package:journal/utils.dart'; +import 'package:path/path.dart'; typedef void NoteSelectedFunction(int noteIndex); @@ -48,16 +49,40 @@ class JournalList extends StatelessWidget { } Widget _buildRow(BuildContext context, Note journal, int noteIndex) { - var formatter = DateFormat('dd MMM, yyyy - EE'); - var title = formatter.format(journal.created); + var title = ""; + var time = ""; - var timeFormatter = DateFormat('Hm'); - var time = timeFormatter.format(journal.created); + if (journal.hasValidDate()) { + var formatter = DateFormat('dd MMM, yyyy - EE'); + title = formatter.format(journal.created); + + var timeFormatter = DateFormat('Hm'); + time = timeFormatter.format(journal.created); + } else { + title = basename(journal.filePath); + } var body = journal.body; body = body.replaceAll("\n", " "); var textTheme = Theme.of(context).textTheme; + var children = []; + if (time.isNotEmpty) { + children.addAll([ + SizedBox(height: 4.0), + Text(time, style: textTheme.body1), + ]); + } + + children.addAll([ + SizedBox(height: 4.0), + Text( + body, + maxLines: 3, + overflow: TextOverflow.ellipsis, + style: textTheme.body1, + ), + ]); var tile = ListTile( isThreeLine: true, @@ -66,17 +91,7 @@ class JournalList extends StatelessWidget { style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500), ), subtitle: Column( - children: [ - SizedBox(height: 4.0), - Text(time, style: textTheme.body1), - SizedBox(height: 4.0), - Text( - body, - maxLines: 3, - overflow: TextOverflow.ellipsis, - style: textTheme.body1, - ), - ], + children: children, crossAxisAlignment: CrossAxisAlignment.start, ), onTap: () => noteSelectedFunction(noteIndex),