Files
GitJournal/lib/widgets/journal_list.dart
Vishesh Handa b9b42d950f ListView: Remove the padding
This way it properly aligns up with the hamburger menu.

I also discovered this 'debugShowMaterialGrid' option which makes
working with padding issues much much easier.
2019-01-23 15:19:54 +01:00

76 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:intl/intl.dart';
import 'package:journal/note.dart';
import 'package:journal/state_container.dart';
typedef void NoteSelectedFunction(int noteIndex);
class JournalList extends StatelessWidget {
final NoteSelectedFunction noteSelectedFunction;
final List<Note> notes;
final _biggerFont = const TextStyle(fontSize: 18.0);
JournalList({
@required this.notes,
@required this.noteSelectedFunction,
});
@override
Widget build(BuildContext context) {
return new ListView.builder(
itemBuilder: (context, i) {
if (i >= notes.length) {
return null;
}
var note = notes[i];
return new Dismissible(
key: new Key(note.fileName),
child: _buildRow(context, note, i),
background: new Container(color: Theme.of(context).accentColor),
onDismissed: (direction) {
final stateContainer = StateContainer.of(context);
stateContainer.removeNote(note);
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text("Note deleted"),
action: new SnackBarAction(
label: 'Undo',
onPressed: () => stateContainer.insertNote(i, note),
),
));
},
);
},
);
}
Widget _buildRow(BuildContext context, Note journal, int noteIndex) {
var formatter = new DateFormat('dd MMM, yyyy');
var title = formatter.format(journal.created);
var timeFormatter = new DateFormat('Hm');
var time = timeFormatter.format(journal.created);
var body = journal.body;
body = body.replaceAll("\n", " ");
return new ListTile(
isThreeLine: true,
title: new Text(
title,
style: _biggerFont,
),
subtitle: new Text(
time + "\n" + body,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
onTap: () => noteSelectedFunction(noteIndex),
);
}
}