Skip to content

Commit

Permalink
[Presentation] Added missing close button in the app_webview.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Sep 16, 2024
1 parent 1963cbc commit 5750ea7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 37 deletions.
49 changes: 24 additions & 25 deletions lib/presentation/daily_check_in/daily_check_in_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,31 @@ class DailyCheckInPage extends StatelessWidget {
child: BlocProvider(
create: (ctx) => Injection.urlPageBloc..add(const UrlPageEvent.init(loadMap: false, loadDailyCheckIn: true)),
child: BlocBuilder<UrlPageBloc, UrlPageState>(
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,
),
),
),
),
);
Expand Down
22 changes: 18 additions & 4 deletions lib/presentation/shared/app_webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AppWebView extends StatelessWidget {
final bool isLoading;
final String? script;
final AppBar? appBar;
final bool showCloseButton;

const AppWebView({
super.key,
Expand All @@ -26,6 +27,7 @@ class AppWebView extends StatelessWidget {
this.isLoading = false,
this.script,
this.appBar,
this.showCloseButton = false,
});

@override
Expand All @@ -37,6 +39,7 @@ class AppWebView extends StatelessWidget {
appBar: appBar,
script: script,
isLoading: isLoading,
showCloseButton: showCloseButton,
);
}

Expand All @@ -48,6 +51,7 @@ class AppWebView extends StatelessWidget {
appBar: appBar,
script: script,
isLoading: isLoading,
showCloseButton: showCloseButton,
);
}

Expand All @@ -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,
Expand All @@ -75,6 +80,7 @@ class _MobileWebView extends StatefulWidget {
this.isLoading = false,
this.script,
this.appBar,
this.showCloseButton = false,
});

@override
Expand All @@ -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(
Expand Down Expand Up @@ -128,13 +137,15 @@ class _DesktopWebView extends StatefulWidget {
final bool isLoading;
final String? script;
final AppBar? appBar;
final bool showCloseButton;

const _DesktopWebView({
required this.url,
required this.hasInternetConnection,
this.isLoading = false,
this.script,
this.appBar,
this.showCloseButton = false,
});

@override
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 16 additions & 8 deletions lib/presentation/shared/loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
}
}
1 change: 1 addition & 0 deletions lib/presentation/shared/page_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5750ea7

Please sign in to comment.