mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
JournalList: Show the fileName if the note has an invalid date
This commit is contained in:
@ -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")) {
|
||||||
|
@ -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),
|
||||||
|
Reference in New Issue
Block a user