diff --git a/catalyst_voices/apps/voices/lib/widgets/document_builder/yes_no_choice_widget.dart b/catalyst_voices/apps/voices/lib/widgets/document_builder/yes_no_choice_widget.dart index fb24af7fc82..b22bf5866dd 100644 --- a/catalyst_voices/apps/voices/lib/widgets/document_builder/yes_no_choice_widget.dart +++ b/catalyst_voices/apps/voices/lib/widgets/document_builder/yes_no_choice_widget.dart @@ -1,31 +1,10 @@ +import 'package:catalyst_voices/common/ext/document_property_ext.dart'; import 'package:catalyst_voices/widgets/widgets.dart'; import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; import 'package:catalyst_voices_models/catalyst_voices_models.dart'; import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart'; import 'package:flutter/material.dart'; -enum _YesNoChoice { - yes(true), - no(false); - - // ignore: avoid_positional_boolean_parameters - const _YesNoChoice(this.value); - - // ignore: avoid_positional_boolean_parameters - static _YesNoChoice fromBool(bool value) { - return _YesNoChoice.values.firstWhere((e) => e.value == value); - } - - final bool value; - - String localizedName(VoicesLocalizations localizations) { - return switch (this) { - yes => localizations.yes, - no => localizations.no, - }; - } -} - class YesNoChoiceWidget extends StatefulWidget { final DocumentProperty property; final ValueChanged onChanged; @@ -47,6 +26,8 @@ class YesNoChoiceWidget extends StatefulWidget { class _YesNoChoiceWidgetState extends State { late bool? selectedValue; + String get _description => widget.property.formattedDescription; + @override void initState() { super.initState(); @@ -73,16 +54,16 @@ class _YesNoChoiceWidgetState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (widget.description.isNotEmpty) ...[ + if (_description.isNotEmpty) ...[ Text( - widget.description, + _description, style: Theme.of(context).textTheme.titleSmall, ), const SizedBox(height: 8), ], _YesNoChoiceSegmentButton( context, - value: widget.property.value, + value: selectedValue, enabled: widget.isEditMode, onChanged: _handleValueChanged, validator: (value) { @@ -103,7 +84,7 @@ class _YesNoChoiceWidgetState extends State { void _handleValueChanged(bool? value) { setState(() { - selectedValue = widget.property.value; + selectedValue = value; }); if (value == null && widget.property.value != value) { _notifyChangeListener(value); diff --git a/catalyst_voices/apps/voices/lib/widgets/tiles/document_builder_section_tile.dart b/catalyst_voices/apps/voices/lib/widgets/tiles/document_builder_section_tile.dart index 0bc2498aebb..87cb6fe62d9 100644 --- a/catalyst_voices/apps/voices/lib/widgets/tiles/document_builder_section_tile.dart +++ b/catalyst_voices/apps/voices/lib/widgets/tiles/document_builder_section_tile.dart @@ -2,8 +2,8 @@ import 'package:catalyst_voices/widgets/document_builder/agreement_confirmation_ import 'package:catalyst_voices/widgets/document_builder/document_token_value_widget.dart'; import 'package:catalyst_voices/widgets/document_builder/single_dropdown_selection_widget.dart'; import 'package:catalyst_voices/widgets/document_builder/single_grouped_tag_selector_widget.dart'; -import 'package:catalyst_voices/widgets/document_builder/yes_no_choice_widget.dart'; import 'package:catalyst_voices/widgets/document_builder/single_line_https_url_widget.dart.dart'; +import 'package:catalyst_voices/widgets/document_builder/yes_no_choice_widget.dart'; import 'package:catalyst_voices/widgets/widgets.dart'; import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; import 'package:catalyst_voices_models/catalyst_voices_models.dart'; @@ -278,7 +278,6 @@ class _PropertyBuilder extends StatelessWidget { return YesNoChoiceWidget( property: castProperty, onChanged: onChanged, - description: castProperty.schema.description ?? '', isEditMode: isEditMode, isRequired: castProperty.schema.isRequired, ); diff --git a/catalyst_voices/packages/internal/catalyst_voices_models/lib/src/document/definitions/yes_no_choice_definition.dart b/catalyst_voices/packages/internal/catalyst_voices_models/lib/src/document/definitions/yes_no_choice_definition.dart index 45144c62874..6cefc153d3a 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_models/lib/src/document/definitions/yes_no_choice_definition.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_models/lib/src/document/definitions/yes_no_choice_definition.dart @@ -16,6 +16,7 @@ final class YesNoChoiceDefinition extends BaseDocumentDefinition { DocumentSchemaProperty schema, bool? value, ) { + // TODO(dtscalac): validate yes no choice return DocumentValidator.validateBool(schema, value); }