JournalList: Show the fileName if the note has an invalid date

This commit is contained in:
Vishesh Handa
2019-02-16 19:57:20 +01:00
parent eb617eafa0
commit 139f1bc5cd
2 changed files with 35 additions and 15 deletions

View File

@ -16,6 +16,11 @@ class Note implements Comparable<Note> {
} }
} }
bool hasValidDate() {
// Arbitrary number, when we set the year = 0, it becomes 1, somehow
return created.year > 10;
}
factory Note.fromJson(Map<String, dynamic> json) { factory Note.fromJson(Map<String, dynamic> json) {
String filePath = ""; String filePath = "";
if (json.containsKey("filePath")) { if (json.containsKey("filePath")) {

View File

@ -4,6 +4,7 @@ import 'package:intl/intl.dart';
import 'package:journal/note.dart'; import 'package:journal/note.dart';
import 'package:journal/state_container.dart'; import 'package:journal/state_container.dart';
import 'package:journal/utils.dart'; import 'package:journal/utils.dart';
import 'package:path/path.dart';
typedef void NoteSelectedFunction(int noteIndex); typedef void NoteSelectedFunction(int noteIndex);
@ -48,16 +49,40 @@ class JournalList extends StatelessWidget {
} }
Widget _buildRow(BuildContext context, Note journal, int noteIndex) { Widget _buildRow(BuildContext context, Note journal, int noteIndex) {
var title = "";
var time = "";
if (journal.hasValidDate()) {
var formatter = DateFormat('dd MMM, yyyy - EE'); var formatter = DateFormat('dd MMM, yyyy - EE');
var title = formatter.format(journal.created); title = formatter.format(journal.created);
var timeFormatter = DateFormat('Hm'); var timeFormatter = DateFormat('Hm');
var time = timeFormatter.format(journal.created); time = timeFormatter.format(journal.created);
} else {
title = basename(journal.filePath);
}
var body = journal.body; var body = journal.body;
body = body.replaceAll("\n", " "); body = body.replaceAll("\n", " ");
var textTheme = Theme.of(context).textTheme; var textTheme = Theme.of(context).textTheme;
var children = <Widget>[];
if (time.isNotEmpty) {
children.addAll(<Widget>[
SizedBox(height: 4.0),
Text(time, style: textTheme.body1),
]);
}
children.addAll(<Widget>[
SizedBox(height: 4.0),
Text(
body,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: textTheme.body1,
),
]);
var tile = ListTile( var tile = ListTile(
isThreeLine: true, isThreeLine: true,
@ -66,17 +91,7 @@ class JournalList extends StatelessWidget {
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500), style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
), ),
subtitle: Column( subtitle: Column(
children: <Widget>[ children: children,
SizedBox(height: 4.0),
Text(time, style: textTheme.body1),
SizedBox(height: 4.0),
Text(
body,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: textTheme.body1,
),
],
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
), ),
onTap: () => noteSelectedFunction(noteIndex), onTap: () => noteSelectedFunction(noteIndex),