From 496a10a444dc84c5320dd32dcf680deba3973fa0 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Thu, 29 Sep 2022 16:35:16 -0400 Subject: [PATCH] Added pull-to-refresh on App page when no webpage shown --- lib/pages/app.dart | 137 +++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 60 deletions(-) diff --git a/lib/pages/app.dart b/lib/pages/app.dart index c4de228..dd5e24c 100644 --- a/lib/pages/app.dart +++ b/lib/pages/app.dart @@ -35,67 +35,84 @@ class _AppPageState extends State { return Scaffold( appBar: settingsProvider.showAppWebpage ? AppBar() : null, backgroundColor: Theme.of(context).colorScheme.surface, - body: settingsProvider.showAppWebpage - ? WebView( - initialUrl: app?.app.url, - javascriptMode: JavascriptMode.unrestricted, - ) - : Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Text( - app?.app.name ?? 'App', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.displayLarge, - ), - Text( - 'By ${app?.app.author ?? 'Unknown'}', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.headlineMedium, - ), - const SizedBox( - height: 32, - ), - GestureDetector( - onTap: () { - if (app?.app.url != null) { - launchUrlString(app?.app.url ?? '', - mode: LaunchMode.externalApplication); - } - }, - child: Text( - app?.app.url ?? '', - textAlign: TextAlign.center, - style: const TextStyle( - decoration: TextDecoration.underline, - fontStyle: FontStyle.italic, - fontSize: 12), - )), - const SizedBox( - height: 32, - ), - Text( - 'Latest Version: ${app?.app.latestVersion ?? 'Unknown'}', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.bodyLarge, - ), - Text( - 'Installed Version: ${app?.app.installedVersion ?? 'None'}', - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.bodyLarge, - ), - const SizedBox( - height: 32, - ), - Text( - 'Last Update Check: ${app?.app.lastUpdateCheck == null ? 'Never' : '\n${app?.app.lastUpdateCheck?.toLocal()}'}', - textAlign: TextAlign.center, - style: const TextStyle( - fontStyle: FontStyle.italic, fontSize: 12), + body: RefreshIndicator( + child: settingsProvider.showAppWebpage + ? WebView( + initialUrl: app?.app.url, + javascriptMode: JavascriptMode.unrestricted, ) - ], - ), + : CustomScrollView( + slivers: [ + SliverFillRemaining( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text( + app?.app.name ?? 'App', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.displayLarge, + ), + Text( + 'By ${app?.app.author ?? 'Unknown'}', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.headlineMedium, + ), + const SizedBox( + height: 32, + ), + GestureDetector( + onTap: () { + if (app?.app.url != null) { + launchUrlString(app?.app.url ?? '', + mode: LaunchMode.externalApplication); + } + }, + child: Text( + app?.app.url ?? '', + textAlign: TextAlign.center, + style: const TextStyle( + decoration: TextDecoration.underline, + fontStyle: FontStyle.italic, + fontSize: 12), + )), + const SizedBox( + height: 32, + ), + Text( + 'Latest Version: ${app?.app.latestVersion ?? 'Unknown'}', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.bodyLarge, + ), + Text( + 'Installed Version: ${app?.app.installedVersion ?? 'None'}', + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.bodyLarge, + ), + const SizedBox( + height: 32, + ), + Text( + 'Last Update Check: ${app?.app.lastUpdateCheck == null ? 'Never' : '\n${app?.app.lastUpdateCheck?.toLocal()}'}', + textAlign: TextAlign.center, + style: const TextStyle( + fontStyle: FontStyle.italic, fontSize: 12), + ) + ], + )), + ], + ), + onRefresh: () async { + if (app != null) { + try { + await appsProvider.getUpdate(app.app.id); + } catch (e) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(e.toString())), + ); + } + } + }), bottomSheet: Padding( padding: EdgeInsets.fromLTRB( 0, 0, 0, MediaQuery.of(context).padding.bottom),