diff --git a/lib/home_page.dart b/lib/home_page.dart index 438eff5..6ac021f 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -93,6 +93,12 @@ class _MyHomePageState extends State with FullScreenListener { return sheets; } + Future _refreshSheets() async { + setState(() { + sheets = acquireSheets(); + }); + } + Future _logOut() async { // Delete saved jwt await _storageHelper.writeSecure(SecureStorageKey.jwt, null); @@ -189,41 +195,45 @@ class _MyHomePageState extends State with FullScreenListener { // Icon for drawer appears automatically appBar: AppBar(title: const Text("Sheetless")), endDrawer: _buildDrawer(), - body: FutureBuilder( - future: sheets, - builder: (BuildContext context, AsyncSnapshot> 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> 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()); + } + }, + ), ), ); }