Implement refresh on drag down

This commit is contained in:
2026-01-24 20:06:56 +01:00
parent 11140a748a
commit f564a39975

View File

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