Skip to content

Commit ac2f878

Browse files
committed
feat(local_ads_management): add option to save interstitial ad as draft or publish
- Implement a dialog to let users choose between saving as a draft or publishing the ad - Update save button functionality to handle both draft and publish actions - Add new events to CreateLocalInterstitialAdBloc for handling draft and publish actions
1 parent 49533c2 commit ac2f878

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

lib/local_ads_management/view/create_local_interstitial_ad_page.dart

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ class _CreateLocalInterstitialAdViewState
5555
super.dispose();
5656
}
5757

58+
/// Shows a dialog to the user to choose between publishing or saving as draft.
59+
Future<ContentStatus?> _showSaveOptionsDialog(BuildContext context) async {
60+
final l10n = AppLocalizationsX(context).l10n;
61+
return showDialog<ContentStatus>(
62+
context: context,
63+
builder: (context) => AlertDialog(
64+
title: Text(l10n.saveAdTitle),
65+
content: Text(l10n.saveAdMessage),
66+
actions: [
67+
TextButton(
68+
onPressed: () => Navigator.of(context).pop(ContentStatus.draft),
69+
child: Text(l10n.saveAsDraft),
70+
),
71+
TextButton(
72+
onPressed: () => Navigator.of(context).pop(ContentStatus.active),
73+
child: Text(l10n.publish),
74+
),
75+
],
76+
),
77+
);
78+
}
79+
5880
@override
5981
Widget build(BuildContext context) {
6082
final l10n = AppLocalizationsX(context).l10n;
@@ -81,9 +103,22 @@ class _CreateLocalInterstitialAdViewState
81103
icon: const Icon(Icons.save),
82104
tooltip: l10n.saveChanges,
83105
onPressed: state.isFormValid
84-
? () => context.read<CreateLocalInterstitialAdBloc>().add(
85-
const CreateLocalInterstitialAdSubmitted(),
86-
)
106+
? () async {
107+
final selectedStatus = await _showSaveOptionsDialog(
108+
context,
109+
);
110+
if (selectedStatus == ContentStatus.active &&
111+
context.mounted) {
112+
context.read<CreateLocalInterstitialAdBloc>().add(
113+
const CreateLocalInterstitialAdPublished(),
114+
);
115+
} else if (selectedStatus == ContentStatus.draft &&
116+
context.mounted) {
117+
context.read<CreateLocalInterstitialAdBloc>().add(
118+
const CreateLocalInterstitialAdSavedAsDraft(),
119+
);
120+
}
121+
}
87122
: null,
88123
);
89124
},

0 commit comments

Comments
 (0)