Give some widgets keys

This should result in a bit of a performance boost. I'm not sure if I
understand the concept of keys correctly, though.
This commit is contained in:
Vishesh Handa
2019-02-16 19:24:54 +01:00
parent 0762bd98c3
commit 62f22ef18d
2 changed files with 7 additions and 4 deletions

View File

@ -36,7 +36,11 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
controller: pageController,
itemCount: widget.notes.length,
itemBuilder: (BuildContext context, int pos) {
return NoteViewer(note: widget.notes[pos]);
var note = widget.notes[pos];
return NoteViewer(
key: ValueKey("Viewer_" + note.filePath),
note: widget.notes[pos],
);
},
);
@ -114,7 +118,7 @@ class NoteViewer extends StatelessWidget {
final Note note;
final _biggerFont = const TextStyle(fontSize: 18.0);
const NoteViewer({@required this.note});
const NoteViewer({Key key, @required this.note}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@ -31,7 +31,7 @@ class JournalList extends StatelessWidget {
var note = notes[i];
return Dismissible(
key: Key(note.filePath),
key: ValueKey("JournalList_" + note.filePath),
child: _buildRow(context, note, i),
background: Container(color: Theme.of(context).accentColor),
onDismissed: (direction) {
@ -60,7 +60,6 @@ class JournalList extends StatelessWidget {
var textTheme = Theme.of(context).textTheme;
var tile = ListTile(
key: ValueKey(journal.filePath),
isThreeLine: true,
title: Text(
title,