JournalListingScreen: Convert to stateful widget

This way we avoid re-sorting the list each time we render it.
This commit is contained in:
Vishesh Handa
2020-02-09 18:56:13 +01:00
parent 2bc1c0aea8
commit 313aace7fb

View File

@ -13,11 +13,24 @@ import 'package:gitjournal/widgets/journal_list.dart';
import 'package:gitjournal/widgets/note_search_delegate.dart';
import 'package:gitjournal/widgets/sync_button.dart';
class JournalListingScreen extends StatelessWidget {
class JournalListingScreen extends StatefulWidget {
final NotesFolder notesFolder;
JournalListingScreen({@required this.notesFolder});
@override
_JournalListingScreenState createState() => _JournalListingScreenState();
}
class _JournalListingScreenState extends State<JournalListingScreen> {
SortedNotesFolder sortedNotesFolder;
@override
void initState() {
super.initState();
sortedNotesFolder = SortedNotesFolder(widget.notesFolder);
}
@override
Widget build(BuildContext context) {
final container = StateContainer.of(context);
@ -29,7 +42,9 @@ class JournalListingScreen extends StatelessWidget {
child: Icon(Icons.add),
);
var title = notesFolder.parent == null ? "Notes" : notesFolder.pathSpec();
var title = widget.notesFolder.parent == null
? "Notes"
: widget.notesFolder.pathSpec();
return Scaffold(
appBar: AppBar(
@ -42,7 +57,7 @@ class JournalListingScreen extends StatelessWidget {
onPressed: () {
showSearch(
context: context,
delegate: NoteSearchDelegate(notesFolder.notes),
delegate: NoteSearchDelegate(sortedNotesFolder.notes),
);
},
),
@ -52,7 +67,7 @@ class JournalListingScreen extends StatelessWidget {
body: Center(
child: Builder(
builder: (context) => RefreshIndicator(
child: Scrollbar(child: buildJournalList(notesFolder)),
child: Scrollbar(child: buildJournalList(sortedNotesFolder)),
onRefresh: () async => _syncRepo(context),
),
),
@ -72,7 +87,7 @@ class JournalListingScreen extends StatelessWidget {
void _newPost(BuildContext context) {
var route = MaterialPageRoute(
builder: (context) => NoteEditor.newNote(notesFolder));
builder: (context) => NoteEditor.newNote(widget.notesFolder));
Navigator.of(context).push(route);
}