|
| 1 | +import 'package:catalyst_voices/widgets/modals/details/voices_align_title_header.dart'; |
| 2 | +import 'package:catalyst_voices/widgets/widgets.dart'; |
| 3 | +import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart'; |
| 4 | +import 'package:catalyst_voices_brands/catalyst_voices_brands.dart'; |
| 5 | +import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; |
| 6 | +import 'package:catalyst_voices_models/catalyst_voices_models.dart'; |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
| 9 | + |
| 10 | +class CampaignManagementDialog extends StatefulWidget { |
| 11 | + final CampaignPublish? initialValue; |
| 12 | + const CampaignManagementDialog._(this.initialValue); |
| 13 | + |
| 14 | + static Future<CampaignPublish?> show( |
| 15 | + BuildContext context, |
| 16 | + CampaignPublish? initialValue, |
| 17 | + ) async { |
| 18 | + final result = await VoicesDialog.show<CampaignPublish?>( |
| 19 | + context: context, |
| 20 | + builder: (context) => CampaignManagementDialog._(initialValue), |
| 21 | + ); |
| 22 | + |
| 23 | + return result; |
| 24 | + } |
| 25 | + |
| 26 | + @override |
| 27 | + State<StatefulWidget> createState() => _CampaignManagementDialogState(); |
| 28 | +} |
| 29 | + |
| 30 | +class _CampaignManagementDialogState extends State<CampaignManagementDialog> { |
| 31 | + late CampaignPublish _campaignSetup; |
| 32 | + |
| 33 | + @override |
| 34 | + void initState() { |
| 35 | + super.initState(); |
| 36 | + _campaignSetup = widget.initialValue ?? CampaignPublish.draft; |
| 37 | + } |
| 38 | + |
| 39 | + @override |
| 40 | + Widget build(BuildContext context) { |
| 41 | + return VoicesDetailsDialog( |
| 42 | + constraints: const BoxConstraints(maxWidth: 750, maxHeight: 270), |
| 43 | + backgroundColor: Theme.of(context).colors.elevationsOnSurfaceNeutralLv0, |
| 44 | + header: VoicesAlignTitleHeader( |
| 45 | + title: context.l10n.campaignManagement, |
| 46 | + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 24), |
| 47 | + ), |
| 48 | + body: Padding( |
| 49 | + padding: const EdgeInsets.fromLTRB(24, 12, 24, 24), |
| 50 | + child: Column( |
| 51 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 52 | + children: [ |
| 53 | + Text( |
| 54 | + context.l10n.status, |
| 55 | + style: Theme.of(context).textTheme.titleSmall, |
| 56 | + ), |
| 57 | + const SizedBox(height: 8), |
| 58 | + _CampaignPublishSegmentButton( |
| 59 | + value: _campaignSetup, |
| 60 | + onChanged: (value) => _campaignSetup = value, |
| 61 | + ), |
| 62 | + const Spacer(), |
| 63 | + Align( |
| 64 | + alignment: Alignment.centerRight, |
| 65 | + child: VoicesFilledButton( |
| 66 | + child: Text(context.l10n.saveButtonText), |
| 67 | + onTap: () { |
| 68 | + Navigator.of(context).pop(_campaignSetup); |
| 69 | + context |
| 70 | + .read<CampaignBuilderCubit>() |
| 71 | + .updateCampaignStatus(_campaignSetup); |
| 72 | + }, |
| 73 | + ), |
| 74 | + ), |
| 75 | + ], |
| 76 | + ), |
| 77 | + ), |
| 78 | + ); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +class _CampaignPublishSegmentButton extends StatefulWidget { |
| 83 | + final CampaignPublish value; |
| 84 | + final ValueChanged<CampaignPublish> onChanged; |
| 85 | + |
| 86 | + const _CampaignPublishSegmentButton({ |
| 87 | + required this.value, |
| 88 | + required this.onChanged, |
| 89 | + }); |
| 90 | + |
| 91 | + @override |
| 92 | + State<_CampaignPublishSegmentButton> createState() => _SingleChoiceState(); |
| 93 | +} |
| 94 | + |
| 95 | +class _SingleChoiceState extends State<_CampaignPublishSegmentButton> { |
| 96 | + late CampaignPublish _segmentValue; |
| 97 | + |
| 98 | + @override |
| 99 | + void initState() { |
| 100 | + super.initState(); |
| 101 | + _segmentValue = widget.value; |
| 102 | + } |
| 103 | + |
| 104 | + @override |
| 105 | + Widget build(BuildContext context) { |
| 106 | + return VoicesSegmentedButton<CampaignPublish>( |
| 107 | + showSelectedIcon: false, |
| 108 | + segments: <ButtonSegment<CampaignPublish>>[ |
| 109 | + ButtonSegment<CampaignPublish>( |
| 110 | + value: CampaignPublish.draft, |
| 111 | + label: Text(context.l10n.draft), |
| 112 | + ), |
| 113 | + ButtonSegment<CampaignPublish>( |
| 114 | + value: CampaignPublish.published, |
| 115 | + label: Text(context.l10n.published), |
| 116 | + ), |
| 117 | + ], |
| 118 | + selected: <CampaignPublish>{_segmentValue}, |
| 119 | + onChanged: (Set<CampaignPublish> newSelection) { |
| 120 | + setState(() { |
| 121 | + _segmentValue = newSelection.first; |
| 122 | + }); |
| 123 | + widget.onChanged(_segmentValue); |
| 124 | + }, |
| 125 | + ); |
| 126 | + } |
| 127 | +} |
0 commit comments