Allow the notes to be refreshed by pulling from the top

This commit is contained in:
Vishesh Handa
2019-01-15 15:26:15 +01:00
parent 075d353447
commit 5a2b0f1f4b
2 changed files with 45 additions and 11 deletions

View File

@ -17,22 +17,29 @@ class HomeScreen extends StatelessWidget {
child: new Icon(Icons.add), child: new Icon(Icons.add),
); );
var journalList = JournalList(
notes: appState.notes,
noteSelectedFunction: (noteIndex) {
var route = new MaterialPageRoute(
builder: (context) => new NoteBrowsingScreen(
notes: appState.notes,
noteIndex: noteIndex,
),
);
Navigator.of(context).push(route);
},
);
return new Scaffold( return new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text('GitJournal'), title: new Text('GitJournal'),
), ),
floatingActionButton: createButton, floatingActionButton: createButton,
body: new JournalList( body: Center(
notes: appState.notes, child: RefreshIndicator(
noteSelectedFunction: (noteIndex) { child: journalList,
var route = new MaterialPageRoute( onRefresh: container.syncNotes,
builder: (context) => new NoteBrowsingScreen( ),
notes: appState.notes,
noteIndex: noteIndex,
),
);
Navigator.of(context).push(route);
},
), ),
drawer: new AppDrawer(), drawer: new AppDrawer(),
); );

View File

@ -96,6 +96,33 @@ class StateContainerState extends State<StateContainer> {
}); });
} }
Future syncNotes() async {
try {
await noteRepo.sync();
} catch (err, stack) {
print("Notes Repo Sync Error: " + err.toString());
print(stack.toString());
return true;
}
try {
appState.isLoadingFromDisk = true;
var loadedNotes = await noteRepo.listNotes();
setState(() {
appState.isLoadingFromDisk = false;
appState.notes = loadedNotes;
});
} catch (err, stack) {
setState(() {
print("Load Notes From Disk Error: " + err.toString());
print(stack.toString());
appState.isLoadingFromDisk = false;
});
}
return true;
}
void _syncNotes() { void _syncNotes() {
print("Starting to syncNOtes"); print("Starting to syncNOtes");
this.noteRepo.sync().then((loaded) { this.noteRepo.sync().then((loaded) {