Implement refresh on drag down
This commit is contained in:
@@ -93,6 +93,12 @@ class _MyHomePageState extends State<MyHomePage> with FullScreenListener {
|
||||
return sheets;
|
||||
}
|
||||
|
||||
Future<void> _refreshSheets() async {
|
||||
setState(() {
|
||||
sheets = acquireSheets();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _logOut() async {
|
||||
// Delete saved jwt
|
||||
await _storageHelper.writeSecure(SecureStorageKey.jwt, null);
|
||||
@@ -189,41 +195,45 @@ class _MyHomePageState extends State<MyHomePage> with FullScreenListener {
|
||||
// Icon for drawer appears automatically
|
||||
appBar: AppBar(title: const Text("Sheetless")),
|
||||
endDrawer: _buildDrawer(),
|
||||
body: FutureBuilder(
|
||||
future: sheets,
|
||||
builder: (BuildContext context, AsyncSnapshot<List<Sheet>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return SheetsWidget(
|
||||
sheets: snapshot.data!,
|
||||
onSheetOpenRequest: (sheet) {
|
||||
_storageHelper.writeSheetAccessTime(sheet.uuid, DateTime.now());
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SheetViewerPage(
|
||||
sheet: sheet,
|
||||
apiClient: apiClient!,
|
||||
config: widget.config,
|
||||
body: RefreshIndicator(
|
||||
onRefresh: _refreshSheets,
|
||||
child: FutureBuilder(
|
||||
future: sheets,
|
||||
builder: (BuildContext context, AsyncSnapshot<List<Sheet>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return SheetsWidget(
|
||||
sheets: snapshot.data!,
|
||||
onSheetOpenRequest: (sheet) {
|
||||
_storageHelper.writeSheetAccessTime(
|
||||
sheet.uuid, DateTime.now());
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SheetViewerPage(
|
||||
sheet: sheet,
|
||||
apiClient: apiClient!,
|
||||
config: widget.config,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
log.warning("Error loading sheets:", snapshot.error);
|
||||
return Center(
|
||||
child: Text(
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.displaySmall!.copyWith(color: Colors.red),
|
||||
textAlign: TextAlign.center,
|
||||
snapshot.error.toString(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
log.warning("Error loading sheets:", snapshot.error);
|
||||
return Center(
|
||||
child: Text(
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.displaySmall!.copyWith(color: Colors.red),
|
||||
textAlign: TextAlign.center,
|
||||
snapshot.error.toString(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user