diff --git a/lib/presentation/daily_check_in/daily_check_in_page.dart b/lib/presentation/daily_check_in/daily_check_in_page.dart index 8eff8d7f..3917f82f 100644 --- a/lib/presentation/daily_check_in/daily_check_in_page.dart +++ b/lib/presentation/daily_check_in/daily_check_in_page.dart @@ -43,32 +43,31 @@ class DailyCheckInPage extends StatelessWidget { child: BlocProvider( create: (ctx) => Injection.urlPageBloc..add(const UrlPageEvent.init(loadMap: false, loadDailyCheckIn: true)), child: BlocBuilder( - builder: (context, state) { - return state.map( - loading: (_) => const Loading(), - loaded: (state) => AppWebView( - appBar: AppBar( - title: Text(s.dailyCheckIn), - actions: [ - IconButton( - icon: const Icon(Icons.info), - splashRadius: Styles.mediumButtonSplashRadius, - onPressed: () => _showInfoDialog(context), - ), - IconButton( - icon: const Icon(Icons.open_in_new), - splashRadius: Styles.mediumButtonSplashRadius, - onPressed: () => _launchUrl(state.dailyCheckInUrl), - ), - ], - ), - url: state.dailyCheckInUrl, - userAgent: state.userAgent, - hasInternetConnection: state.hasInternetConnection, - script: _script, + builder: (context, state) => state.map( + loading: (_) => const Loading(showCloseButton: true), + loaded: (state) => AppWebView( + appBar: AppBar( + title: Text(s.dailyCheckIn), + actions: [ + IconButton( + icon: const Icon(Icons.info), + splashRadius: Styles.mediumButtonSplashRadius, + onPressed: () => _showInfoDialog(context), + ), + IconButton( + icon: const Icon(Icons.open_in_new), + splashRadius: Styles.mediumButtonSplashRadius, + onPressed: () => _launchUrl(state.dailyCheckInUrl), + ), + ], ), - ); - }, + url: state.dailyCheckInUrl, + userAgent: state.userAgent, + hasInternetConnection: state.hasInternetConnection, + script: _script, + showCloseButton: true, + ), + ), ), ), ); diff --git a/lib/presentation/shared/app_webview.dart b/lib/presentation/shared/app_webview.dart index 7f66fafc..99ccb43e 100644 --- a/lib/presentation/shared/app_webview.dart +++ b/lib/presentation/shared/app_webview.dart @@ -17,6 +17,7 @@ class AppWebView extends StatelessWidget { final bool isLoading; final String? script; final AppBar? appBar; + final bool showCloseButton; const AppWebView({ super.key, @@ -26,6 +27,7 @@ class AppWebView extends StatelessWidget { this.isLoading = false, this.script, this.appBar, + this.showCloseButton = false, }); @override @@ -37,6 +39,7 @@ class AppWebView extends StatelessWidget { appBar: appBar, script: script, isLoading: isLoading, + showCloseButton: showCloseButton, ); } @@ -48,6 +51,7 @@ class AppWebView extends StatelessWidget { appBar: appBar, script: script, isLoading: isLoading, + showCloseButton: showCloseButton, ); } @@ -67,6 +71,7 @@ class _MobileWebView extends StatefulWidget { final bool isLoading; final String? script; final AppBar? appBar; + final bool showCloseButton; const _MobileWebView({ required this.url, @@ -75,6 +80,7 @@ class _MobileWebView extends StatefulWidget { this.isLoading = false, this.script, this.appBar, + this.showCloseButton = false, }); @override @@ -88,10 +94,13 @@ class _MobileWebViewState extends State<_MobileWebView> { Widget build(BuildContext context) { if (!widget.hasInternetConnection) { final s = S.of(context); - return PageMessage(text: s.noInternetConnection); + final children = [ + if (widget.showCloseButton) const LoadingCloseButton(), + ]; + return PageMessage(text: s.noInternetConnection, children: children); } if (widget.isLoading) { - return const Loading(); + return Loading(showCloseButton: widget.showCloseButton); } final device = getDeviceType(MediaQuery.of(context).size); return Stack( @@ -128,6 +137,7 @@ class _DesktopWebView extends StatefulWidget { final bool isLoading; final String? script; final AppBar? appBar; + final bool showCloseButton; const _DesktopWebView({ required this.url, @@ -135,6 +145,7 @@ class _DesktopWebView extends StatefulWidget { this.isLoading = false, this.script, this.appBar, + this.showCloseButton = false, }); @override @@ -177,10 +188,13 @@ class _DesktopWebViewState extends State<_DesktopWebView> { Widget build(BuildContext context) { if (!widget.hasInternetConnection) { final s = S.of(context); - return PageMessage(text: s.noInternetConnection); + final children = [ + if (widget.showCloseButton) const LoadingCloseButton(), + ]; + return PageMessage(text: s.noInternetConnection, children: children); } if (widget.isLoading) { - return const Loading(); + return Loading(showCloseButton: widget.showCloseButton); } return Scaffold( appBar: widget.appBar, diff --git a/lib/presentation/shared/loading.dart b/lib/presentation/shared/loading.dart index a6f180cf..5932229d 100644 --- a/lib/presentation/shared/loading.dart +++ b/lib/presentation/shared/loading.dart @@ -38,17 +38,25 @@ class Loading extends StatelessWidget { margin: const EdgeInsets.only(top: 5), child: Text(s.loading, textAlign: TextAlign.center), ), - if (showCloseButton) - Center( - child: IconButton.filled( - onPressed: () => Navigator.pop(context), - icon: const Icon(Icons.close), - splashRadius: Styles.mediumButtonSplashRadius, - ), - ), + if (showCloseButton) const LoadingCloseButton(), ], ); if (!useScaffold) return body; return Scaffold(body: body); } } + +class LoadingCloseButton extends StatelessWidget { + const LoadingCloseButton({super.key}); + + @override + Widget build(BuildContext context) { + return Center( + child: IconButton.filled( + onPressed: () => Navigator.pop(context), + icon: const Icon(Icons.close), + splashRadius: Styles.mediumButtonSplashRadius, + ), + ); + } +} diff --git a/lib/presentation/shared/page_message.dart b/lib/presentation/shared/page_message.dart index 0fe77605..fe37de12 100644 --- a/lib/presentation/shared/page_message.dart +++ b/lib/presentation/shared/page_message.dart @@ -22,6 +22,7 @@ class PageMessage extends StatelessWidget { margin: const EdgeInsets.only(top: 5), child: Text(text, textAlign: TextAlign.center), ), + ...children, ], ); if (!useScaffold) return body;