Skip to content

Commit d99dbcd

Browse files
committed
feat(local_ads_management): add option to save local native ads as draft
- Implement dialog for choosing between publishing or saving as draft - Update save button functionality to handle both options - Add new events to CreateLocalNativeAdBloc for publishing and saving as draft
1 parent ac2f878 commit d99dbcd

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

lib/local_ads_management/view/create_local_native_ad_page.dart

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ class _CreateLocalNativeAdViewState extends State<_CreateLocalNativeAdView> {
6060
super.dispose();
6161
}
6262

63+
/// Shows a dialog to the user to choose between publishing or saving as draft.
64+
Future<ContentStatus?> _showSaveOptionsDialog(BuildContext context) async {
65+
final l10n = AppLocalizationsX(context).l10n;
66+
return showDialog<ContentStatus>(
67+
context: context,
68+
builder: (context) => AlertDialog(
69+
title: Text(l10n.saveAdTitle),
70+
content: Text(l10n.saveAdMessage),
71+
actions: [
72+
TextButton(
73+
onPressed: () => Navigator.of(context).pop(ContentStatus.draft),
74+
child: Text(l10n.saveAsDraft),
75+
),
76+
TextButton(
77+
onPressed: () => Navigator.of(context).pop(ContentStatus.active),
78+
child: Text(l10n.publish),
79+
),
80+
],
81+
),
82+
);
83+
}
84+
6385
@override
6486
Widget build(BuildContext context) {
6587
final l10n = AppLocalizationsX(context).l10n;
@@ -83,9 +105,22 @@ class _CreateLocalNativeAdViewState extends State<_CreateLocalNativeAdView> {
83105
icon: const Icon(Icons.save),
84106
tooltip: l10n.saveChanges,
85107
onPressed: state.isFormValid
86-
? () => context.read<CreateLocalNativeAdBloc>().add(
87-
const CreateLocalNativeAdSubmitted(),
88-
)
108+
? () async {
109+
final selectedStatus = await _showSaveOptionsDialog(
110+
context,
111+
);
112+
if (selectedStatus == ContentStatus.active &&
113+
context.mounted) {
114+
context.read<CreateLocalNativeAdBloc>().add(
115+
const CreateLocalNativeAdPublished(),
116+
);
117+
} else if (selectedStatus == ContentStatus.draft &&
118+
context.mounted) {
119+
context.read<CreateLocalNativeAdBloc>().add(
120+
const CreateLocalNativeAdSavedAsDraft(),
121+
);
122+
}
123+
}
89124
: null,
90125
);
91126
},

0 commit comments

Comments
 (0)