Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-forge-version
Browse files Browse the repository at this point in the history
  • Loading branch information
kukkok3 authored Jan 10, 2025
2 parents 838b406 + 4ba24ab commit bdfd24f
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _ProposalBuilderGuidanceViewState
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
VoicesDropdown<GuidanceType?>(
FilterByDropdown<GuidanceType?>(
items: GuidanceType.values
.map(
(e) => VoicesDropdownMenuEntry<GuidanceType>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'package:catalyst_voices/widgets/dropdown/voices_dropdown.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter/material.dart';

class SingleDropdownSelectionWidget extends StatefulWidget {
final String value;
final List<String> items;
final DropDownSingleSelectDefinition definition;
final DocumentNodeId nodeId;
final String title;
final bool isEditMode;
final bool isRequired;
final ValueChanged<DocumentChange> onChanged;

const SingleDropdownSelectionWidget({
super.key,
required this.value,
required this.items,
required this.definition,
required this.nodeId,
required this.title,
required this.isEditMode,
required this.isRequired,
required this.onChanged,
});

@override
State<SingleDropdownSelectionWidget> createState() =>
_SingleDropdownSelectionWidgetState();
}

class _SingleDropdownSelectionWidgetState
extends State<SingleDropdownSelectionWidget> {
late List<DropdownMenuEntry<String>> _dropdownMenuEntries;
late TextEditingController _textEditingController;

String? value;

List<DropdownMenuEntry<String>> get _mapItems {
final items = widget.items;
return items.map((e) => DropdownMenuEntry(value: e, label: e)).toList();
}

@override
void initState() {
super.initState();
_textEditingController = TextEditingController();
_textEditingController.text = widget.value;

_dropdownMenuEntries = _mapItems;
}

@override
void didUpdateWidget(covariant SingleDropdownSelectionWidget oldWidget) {
super.didUpdateWidget(oldWidget);

if (oldWidget.items != widget.items) {
_dropdownMenuEntries = _mapItems;
}
if (oldWidget.isEditMode != widget.isEditMode &&
widget.isEditMode == false) {
final value = widget.value;
_textEditingController.text = value;
}
}

@override
void dispose() {
_textEditingController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
widget.title,
style: Theme.of(context).textTheme.titleSmall,
),
const SizedBox(height: 8),
SingleSelectDropdown(
textEditingController: _textEditingController,
items: _dropdownMenuEntries,
enabled: widget.isEditMode,
onSelected: (val) {
widget.onChanged(DocumentChange(nodeId: widget.nodeId, value: val));
},
initialValue: widget.value,
),
],
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:catalyst_voices/common/ext/string_ext.dart';
import 'package:catalyst_voices/widgets/dropdown/voices_dropdown.dart';
import 'package:catalyst_voices/widgets/widgets.dart';
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
Expand Down Expand Up @@ -185,12 +186,12 @@ class _TagGroupsDropdown extends StatelessWidget {

@override
Widget build(BuildContext context) {
return VoicesDropdownFormField<GroupedTags>(
return SingleSelectDropdown<GroupedTags>(
items: groupedTags
.map((e) => DropdownMenuItem(value: e, child: Text(e.group)))
.map((e) => DropdownMenuEntry(value: e, label: e.group))
.toList(),
value: value,
onChanged: onChanged,
initialValue: value,
onSelected: onChanged,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:flutter/material.dart';

class VoicesDropdown<T> extends StatelessWidget {
class FilterByDropdown<T> extends StatelessWidget {
final List<DropdownMenuEntry<T?>> items;
final ValueChanged<T?>? onChanged;
final T? value;
const VoicesDropdown({
const FilterByDropdown({
super.key,
required this.items,
this.onChanged,
Expand Down Expand Up @@ -72,3 +73,61 @@ class VoicesDropdownMenuEntry<T> extends DropdownMenuEntry<T> {
visualDensity: VisualDensity.compact,
);
}

class SingleSelectDropdown<T> extends StatelessWidget {
final TextEditingController? textEditingController;
final List<DropdownMenuEntry<T>> items;
final T? initialValue;
final bool enabled;
final ValueChanged<T?>? onSelected;
final String? hintText;

const SingleSelectDropdown({
super.key,
this.textEditingController,
this.initialValue,
required this.items,
this.enabled = true,
required this.onSelected,
this.hintText,
});

@override
Widget build(BuildContext context) {
return DropdownMenu(
width: double.infinity,
controller: textEditingController,
initialSelection: initialValue,
enabled: enabled,
hintText: hintText,
dropdownMenuEntries: items,
onSelected: onSelected,
inputDecorationTheme: InputDecorationTheme(
hintStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colors.textDisabled,
),
fillColor: Theme.of(context).colors.elevationsOnSurfaceNeutralLv1Grey,
filled: true,
enabledBorder: _border(context),
disabledBorder: _border(context),
focusedBorder: _border(context),
),
trailingIcon: Offstage(
offstage: !enabled,
child: VoicesAssets.icons.chevronDown.buildIcon(),
),
selectedTrailingIcon: VoicesAssets.icons.chevronUp.buildIcon(),
menuStyle: MenuStyle(
backgroundColor: WidgetStatePropertyAll(
Theme.of(context).colors.elevationsOnSurfaceNeutralLv1Grey,
),
),
);
}

OutlineInputBorder _border(BuildContext context) => OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).colors.outlineBorderVariant!,
),
);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:catalyst_voices/widgets/document_builder/agreement_confirmation_widget.dart';
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/widgets.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
Expand Down Expand Up @@ -208,7 +209,6 @@ class _PropertyBuilder extends StatelessWidget {
case SingleLineHttpsURLEntryDefinition():
case MultiLineTextEntryDefinition():
case MultiLineTextEntryMarkdownDefinition():
case DropDownSingleSelectDefinition():
case MultiSelectDefinition():
case SingleLineTextEntryListDefinition():
case MultiLineTextEntryListMarkdownDefinition():
Expand All @@ -221,7 +221,7 @@ class _PropertyBuilder extends StatelessWidget {
case YesNoChoiceDefinition():
case SPDXLicenceOrUrlDefinition():
case LanguageCodeDefinition():
throw UnimplementedError('${definition.type} not implemented');
throw UnimplementedError();
case SingleGroupedTagSelectorDefinition():
final castProperty = definition.castProperty(property);
return SingleGroupedTagSelectorWidget(
Expand All @@ -232,6 +232,18 @@ class _PropertyBuilder extends StatelessWidget {
onChanged: onChanged,
isRequired: castProperty.schema.isRequired,
);
case DropDownSingleSelectDefinition():
final castProperty = definition.castProperty(property);
return SingleDropdownSelectionWidget(
value: castProperty.value ?? castProperty.schema.defaultValue ?? '',
items: castProperty.schema.enumValues ?? [],
definition: definition,
nodeId: castProperty.schema.nodeId,
title: castProperty.schema.title ?? '',
isEditMode: isEditMode,
isRequired: castProperty.schema.isRequired,
onChanged: onChanged,
);
case AgreementConfirmationDefinition():
final castProperty = definition.castProperty(property);
return AgreementConfirmationWidget(
Expand Down
1 change: 0 additions & 1 deletion catalyst_voices/apps/voices/lib/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export 'containers/space_side_panel.dart';
export 'containers/workspace_text_tile_container.dart';
export 'drawer/voices_drawer.dart';
export 'drawer/voices_drawer_space_chooser.dart';
export 'dropdown/voices_dropdown_form_field.dart';
export 'footers/links_page_footer.dart';
export 'footers/standard_links_page_footer.dart';
export 'headers/brand_header.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
import '../../helpers/helpers.dart';

void main() {
group('VoicesDropdown Widget Tests', () {
group('$FilterByDropdown Widget Tests', () {
late List<DropdownMenuEntry<String>> items;
setUp(() {
items = [
Expand All @@ -23,7 +23,7 @@ void main() {
testWidgets('renders correctly with initial value', (tester) async {
await tester.pumpApp(
Scaffold(
body: VoicesDropdown(
body: FilterByDropdown(
items: items,
value: 'item1',
onChanged: (value) {},
Expand All @@ -49,7 +49,7 @@ void main() {
testWidgets('renders correctly without initial value', (tester) async {
await tester.pumpApp(
Scaffold(
body: VoicesDropdown(
body: FilterByDropdown(
items: items,
onChanged: (value) {},
),
Expand All @@ -73,7 +73,7 @@ void main() {
testWidgets('renders correctly without initial value', (tester) async {
await tester.pumpApp(
Scaffold(
body: VoicesDropdown(
body: FilterByDropdown(
items: items,
onChanged: (value) {},
),
Expand Down Expand Up @@ -103,7 +103,7 @@ void main() {
testWidgets('Changes value correctly', (tester) async {
await tester.pumpApp(
Scaffold(
body: VoicesDropdown(
body: FilterByDropdown(
items: items,
onChanged: (value) {},
),
Expand Down Expand Up @@ -140,7 +140,7 @@ void main() {
final log = <int>[];
await tester.pumpApp(
Scaffold(
body: VoicesDropdown(
body: FilterByDropdown(
items: items,
onChanged: (value) {
log.add(0);
Expand Down

0 comments on commit bdfd24f

Please sign in to comment.