diff --git a/CHANGELOG.md b/CHANGELOG.md index d4a8a21da1..324eac9465 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Bug fixes +* Fix `Dropdown.expanded_insets` having no effect when `expand` is set ([#6895](https://github.com/flet-dev/flet/issues/6895), [#6896](https://github.com/flet-dev/flet/pull/6896)) by @xsalaices. * Fix `Tabs` ignoring a new `selected_index` set together with a new `length` - e.g. inserting a tab before the selected one and moving `selected_index` to follow it selected the inserted tab instead ([#6901](https://github.com/flet-dev/flet/pull/6901)) by @FeodorFitsner. * Fix controls losing their state (a `TextField` its focus and cursor, a list its scroll position) when a sibling before them in a `Column`, `Row` or other multi-child control became visible or hidden: children were matched by position, so the shift rebuilt them. Children are now matched by control id ([#6901](https://github.com/flet-dev/flet/pull/6901)) by @FeodorFitsner. * Fix `FilePicker.upload()` with several files uploading the wrong file to each URL: after the first upload, each file's `id` pointed at the next picked file, so a file's bytes went to another file's URL and the last file never uploaded (its caller waited forever). Picked files now keep their `id` across `upload()` calls, and files that can't be found report an upload error ([#6901](https://github.com/flet-dev/flet/pull/6901)) by @FeodorFitsner. diff --git a/packages/flet/lib/src/controls/dropdown.dart b/packages/flet/lib/src/controls/dropdown.dart index 9c07d7fbea..2d896110a8 100644 --- a/packages/flet/lib/src/controls/dropdown.dart +++ b/packages/flet/lib/src/controls/dropdown.dart @@ -226,7 +226,9 @@ class _DropdownControlState extends State { _focusNode.canRequestFocus = editable; int expand = widget.control.getExpand("expand", 0)!; - EdgeInsets? expandedInsets = expand > 0 ? EdgeInsets.zero : null; + EdgeInsets? expandedInsets = expand > 0 + ? widget.control.getPadding("expanded_insets", EdgeInsets.zero) + : null; Widget dropDown = DropdownMenu( key: dropdownMenuKey, diff --git a/packages/flet/test/widgets/dropdown_test.dart b/packages/flet/test/widgets/dropdown_test.dart new file mode 100644 index 0000000000..7b223449dc --- /dev/null +++ b/packages/flet/test/widgets/dropdown_test.dart @@ -0,0 +1,91 @@ +import 'package:flet/src/controls/dropdown.dart'; +import 'package:flet/src/flet_backend.dart'; +import 'package:flet/src/models/control.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class _TestBackend extends FletBackend { + _TestBackend() + : super( + pageUri: Uri.parse('http://localhost'), + assetsDir: '', + extensions: [], + multiView: false); +} + +void main() { + testWidgets('Dropdown.expanded_insets is applied when expand is set', + (tester) async { + final backend = _TestBackend(); + final control = Control( + id: 1, + type: 'Dropdown', + properties: { + 'expand': 1, + 'expanded_insets': { + 'left': 40.0, + 'top': 0.0, + 'right': 40.0, + 'bottom': 0.0 + }, + 'options': [], + }, + backend: backend); + + await tester.pumpWidget( + MaterialApp(home: Scaffold(body: DropdownControl(control: control)))); + + expect(tester.takeException(), isNull); + final menu = + tester.widget>(find.byType(DropdownMenu)); + expect(menu.expandedInsets, const EdgeInsets.fromLTRB(40, 0, 40, 0)); + }); + + testWidgets( + 'Dropdown falls back to zero insets when expand is set without expanded_insets', + (tester) async { + final backend = _TestBackend(); + final control = Control( + id: 1, + type: 'Dropdown', + properties: { + 'expand': 1, + 'options': [], + }, + backend: backend); + + await tester.pumpWidget( + MaterialApp(home: Scaffold(body: DropdownControl(control: control)))); + + expect(tester.takeException(), isNull); + final menu = + tester.widget>(find.byType(DropdownMenu)); + expect(menu.expandedInsets, EdgeInsets.zero); + }); + + testWidgets('Dropdown has null expandedInsets when not expanded', + (tester) async { + final backend = _TestBackend(); + final control = Control( + id: 1, + type: 'Dropdown', + properties: { + 'expanded_insets': { + 'left': 40.0, + 'top': 0.0, + 'right': 40.0, + 'bottom': 0.0 + }, + 'options': [], + }, + backend: backend); + + await tester.pumpWidget( + MaterialApp(home: Scaffold(body: DropdownControl(control: control)))); + + expect(tester.takeException(), isNull); + final menu = + tester.widget>(find.byType(DropdownMenu)); + expect(menu.expandedInsets, isNull); + }); +}