mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
JournalListingScreen: Convert to stateful widget
This way we avoid re-sorting the list each time we render it.
This commit is contained in:
@ -13,11 +13,24 @@ import 'package:gitjournal/widgets/journal_list.dart';
|
|||||||
import 'package:gitjournal/widgets/note_search_delegate.dart';
|
import 'package:gitjournal/widgets/note_search_delegate.dart';
|
||||||
import 'package:gitjournal/widgets/sync_button.dart';
|
import 'package:gitjournal/widgets/sync_button.dart';
|
||||||
|
|
||||||
class JournalListingScreen extends StatelessWidget {
|
class JournalListingScreen extends StatefulWidget {
|
||||||
final NotesFolder notesFolder;
|
final NotesFolder notesFolder;
|
||||||
|
|
||||||
JournalListingScreen({@required this.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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final container = StateContainer.of(context);
|
final container = StateContainer.of(context);
|
||||||
@ -29,7 +42,9 @@ class JournalListingScreen extends StatelessWidget {
|
|||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
);
|
);
|
||||||
|
|
||||||
var title = notesFolder.parent == null ? "Notes" : notesFolder.pathSpec();
|
var title = widget.notesFolder.parent == null
|
||||||
|
? "Notes"
|
||||||
|
: widget.notesFolder.pathSpec();
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -42,7 +57,7 @@ class JournalListingScreen extends StatelessWidget {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
showSearch(
|
showSearch(
|
||||||
context: context,
|
context: context,
|
||||||
delegate: NoteSearchDelegate(notesFolder.notes),
|
delegate: NoteSearchDelegate(sortedNotesFolder.notes),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -52,7 +67,7 @@ class JournalListingScreen extends StatelessWidget {
|
|||||||
body: Center(
|
body: Center(
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (context) => RefreshIndicator(
|
builder: (context) => RefreshIndicator(
|
||||||
child: Scrollbar(child: buildJournalList(notesFolder)),
|
child: Scrollbar(child: buildJournalList(sortedNotesFolder)),
|
||||||
onRefresh: () async => _syncRepo(context),
|
onRefresh: () async => _syncRepo(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -72,7 +87,7 @@ class JournalListingScreen extends StatelessWidget {
|
|||||||
|
|
||||||
void _newPost(BuildContext context) {
|
void _newPost(BuildContext context) {
|
||||||
var route = MaterialPageRoute(
|
var route = MaterialPageRoute(
|
||||||
builder: (context) => NoteEditor.newNote(notesFolder));
|
builder: (context) => NoteEditor.newNote(widget.notesFolder));
|
||||||
Navigator.of(context).push(route);
|
Navigator.of(context).push(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user