Skip to content

Commit bb90381

Browse files
committed
refactor(account): remove duplicate limitation bottom sheet code
- Remove duplicate _getBottomSheetContent function from multiple files - Replace custom bottom sheet logic with showContentLimitationBottomSheet function - Remove unnecessary imports and simplify code
1 parent 83a6ca4 commit bb90381

File tree

3 files changed

+6
-183
lines changed

3 files changed

+6
-183
lines changed

lib/account/view/followed_contents/countries/add_country_to_follow_page.dart

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/ava
66
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/app_localizations.dart';
88
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
9-
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
109
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
1110
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
12-
import 'package:go_router/go_router.dart';
1311
import 'package:ui_kit/ui_kit.dart';
1412

1513
class _FollowButton extends StatefulWidget {
@@ -52,23 +50,10 @@ class _FollowButtonState extends State<_FollowButton> {
5250

5351
if (status != LimitationStatus.allowed) {
5452
if (mounted) {
55-
final userRole = context.read<AppBloc>().state.user?.appRole;
56-
final content = _getBottomSheetContent(
53+
showContentLimitationBottomSheet(
5754
context: context,
58-
l10n: l10n,
5955
status: status,
60-
userRole: userRole,
61-
defaultBody: l10n.limitReachedBodyFollow,
62-
);
63-
64-
await showModalBottomSheet<void>(
65-
context: context,
66-
builder: (_) => ContentLimitationBottomSheet(
67-
title: content.title,
68-
body: content.body,
69-
buttonText: content.buttonText,
70-
onButtonPressed: content.onPressed,
71-
),
56+
action: ContentAction.followCountry,
7257
);
7358
}
7459
return;
@@ -126,50 +111,6 @@ class _FollowButtonState extends State<_FollowButton> {
126111
}
127112
}
128113

129-
/// Determines the content for the [ContentLimitationBottomSheet] based on
130-
/// the user's role and the limitation status.
131-
({String title, String body, String buttonText, VoidCallback? onPressed})
132-
_getBottomSheetContent({
133-
required BuildContext context,
134-
required AppLocalizations l10n,
135-
required LimitationStatus status,
136-
required AppUserRole? userRole,
137-
required String defaultBody,
138-
}) {
139-
switch (status) {
140-
case LimitationStatus.anonymousLimitReached:
141-
return (
142-
title: l10n.anonymousLimitTitle,
143-
body: l10n.anonymousLimitBody,
144-
buttonText: l10n.anonymousLimitButton,
145-
onPressed: () {
146-
Navigator.of(context).pop();
147-
context.pushNamed(Routes.accountLinkingName);
148-
},
149-
);
150-
case LimitationStatus.standardUserLimitReached:
151-
// TODO(fulleni): Implement upgrade flow.
152-
return (
153-
title: l10n.standardLimitTitle,
154-
body: l10n.standardLimitBody,
155-
buttonText: l10n.standardLimitButton,
156-
onPressed: () => Navigator.of(context).pop(),
157-
);
158-
case LimitationStatus.premiumUserLimitReached:
159-
return (
160-
title: l10n.premiumLimitTitle,
161-
body: defaultBody,
162-
buttonText: l10n.premiumLimitButton,
163-
onPressed: () {
164-
Navigator.of(context).pop();
165-
context.goNamed(Routes.manageFollowedItemsName);
166-
},
167-
);
168-
case LimitationStatus.allowed:
169-
return (title: '', body: '', buttonText: '', onPressed: null);
170-
}
171-
}
172-
173114
/// {@template add_country_to_follow_page}
174115
/// A page that allows users to browse and select countries to follow.
175116
/// {@endtemplate}

lib/account/view/followed_contents/sources/add_source_to_follow_page.dart

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/ava
66
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/app_localizations.dart';
88
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
9-
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
109
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
1110
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
12-
import 'package:go_router/go_router.dart';
1311
import 'package:ui_kit/ui_kit.dart';
1412

1513
class _FollowButton extends StatefulWidget {
@@ -52,23 +50,10 @@ class _FollowButtonState extends State<_FollowButton> {
5250

5351
if (status != LimitationStatus.allowed) {
5452
if (mounted) {
55-
final userRole = context.read<AppBloc>().state.user?.appRole;
56-
final content = _getBottomSheetContent(
53+
showContentLimitationBottomSheet(
5754
context: context,
58-
l10n: l10n,
5955
status: status,
60-
userRole: userRole,
61-
defaultBody: l10n.limitReachedBodyFollow,
62-
);
63-
64-
await showModalBottomSheet<void>(
65-
context: context,
66-
builder: (_) => ContentLimitationBottomSheet(
67-
title: content.title,
68-
body: content.body,
69-
buttonText: content.buttonText,
70-
onButtonPressed: content.onPressed,
71-
),
56+
action: ContentAction.followSource,
7257
);
7358
}
7459
return;
@@ -126,50 +111,6 @@ class _FollowButtonState extends State<_FollowButton> {
126111
}
127112
}
128113

129-
/// Determines the content for the [ContentLimitationBottomSheet] based on
130-
/// the user's role and the limitation status.
131-
({String title, String body, String buttonText, VoidCallback? onPressed})
132-
_getBottomSheetContent({
133-
required BuildContext context,
134-
required AppLocalizations l10n,
135-
required LimitationStatus status,
136-
required AppUserRole? userRole,
137-
required String defaultBody,
138-
}) {
139-
switch (status) {
140-
case LimitationStatus.anonymousLimitReached:
141-
return (
142-
title: l10n.anonymousLimitTitle,
143-
body: l10n.anonymousLimitBody,
144-
buttonText: l10n.anonymousLimitButton,
145-
onPressed: () {
146-
Navigator.of(context).pop();
147-
context.pushNamed(Routes.accountLinkingName);
148-
},
149-
);
150-
case LimitationStatus.standardUserLimitReached:
151-
// TODO(fulleni): Implement upgrade flow.
152-
return (
153-
title: l10n.standardLimitTitle,
154-
body: l10n.standardLimitBody,
155-
buttonText: l10n.standardLimitButton,
156-
onPressed: () => Navigator.of(context).pop(),
157-
);
158-
case LimitationStatus.premiumUserLimitReached:
159-
return (
160-
title: l10n.premiumLimitTitle,
161-
body: defaultBody,
162-
buttonText: l10n.premiumLimitButton,
163-
onPressed: () {
164-
Navigator.of(context).pop();
165-
context.goNamed(Routes.manageFollowedItemsName);
166-
},
167-
);
168-
case LimitationStatus.allowed:
169-
return (title: '', body: '', buttonText: '', onPressed: null);
170-
}
171-
}
172-
173114
/// {@template add_source_to_follow_page}
174115
/// A page that allows users to browse and select sources to follow.
175116
/// {@endtemplate}

lib/account/view/followed_contents/topics/add_topic_to_follow_page.dart

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/ava
66
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/app_localizations.dart';
88
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
9-
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
109
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
1110
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
12-
import 'package:go_router/go_router.dart';
1311
import 'package:ui_kit/ui_kit.dart';
1412

1513
class _FollowButton extends StatefulWidget {
@@ -52,23 +50,10 @@ class _FollowButtonState extends State<_FollowButton> {
5250

5351
if (status != LimitationStatus.allowed) {
5452
if (mounted) {
55-
final userRole = context.read<AppBloc>().state.user?.appRole;
56-
final content = _getBottomSheetContent(
53+
showContentLimitationBottomSheet(
5754
context: context,
58-
l10n: l10n,
5955
status: status,
60-
userRole: userRole,
61-
defaultBody: l10n.limitReachedBodyFollow,
62-
);
63-
64-
await showModalBottomSheet<void>(
65-
context: context,
66-
builder: (_) => ContentLimitationBottomSheet(
67-
title: content.title,
68-
body: content.body,
69-
buttonText: content.buttonText,
70-
onButtonPressed: content.onPressed,
71-
),
56+
action: ContentAction.followTopic,
7257
);
7358
}
7459
return;
@@ -126,50 +111,6 @@ class _FollowButtonState extends State<_FollowButton> {
126111
}
127112
}
128113

129-
/// Determines the content for the [ContentLimitationBottomSheet] based on
130-
/// the user's role and the limitation status.
131-
({String title, String body, String buttonText, VoidCallback? onPressed})
132-
_getBottomSheetContent({
133-
required BuildContext context,
134-
required AppLocalizations l10n,
135-
required LimitationStatus status,
136-
required AppUserRole? userRole,
137-
required String defaultBody,
138-
}) {
139-
switch (status) {
140-
case LimitationStatus.anonymousLimitReached:
141-
return (
142-
title: l10n.anonymousLimitTitle,
143-
body: l10n.anonymousLimitBody,
144-
buttonText: l10n.anonymousLimitButton,
145-
onPressed: () {
146-
Navigator.of(context).pop();
147-
context.pushNamed(Routes.accountLinkingName);
148-
},
149-
);
150-
case LimitationStatus.standardUserLimitReached:
151-
// TODO(fulleni): Implement upgrade flow.
152-
return (
153-
title: l10n.standardLimitTitle,
154-
body: l10n.standardLimitBody,
155-
buttonText: l10n.standardLimitButton,
156-
onPressed: () => Navigator.of(context).pop(),
157-
);
158-
case LimitationStatus.premiumUserLimitReached:
159-
return (
160-
title: l10n.premiumLimitTitle,
161-
body: defaultBody,
162-
buttonText: l10n.premiumLimitButton,
163-
onPressed: () {
164-
Navigator.of(context).pop();
165-
context.goNamed(Routes.manageFollowedItemsName);
166-
},
167-
);
168-
case LimitationStatus.allowed:
169-
return (title: '', body: '', buttonText: '', onPressed: null);
170-
}
171-
}
172-
173114
/// {@template add_topic_to_follow_page}
174115
/// A page that allows users to browse and select topics to follow.
175116
/// {@endtemplate}

0 commit comments

Comments
 (0)