Skip to content

Commit 0b9b4b9

Browse files
authored
feat: add configurable barrier (backdrop) color (#17)
1 parent eb34605 commit 0b9b4b9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/src/generic_dropdown.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ final class GenericDropdown extends StatefulWidget {
119119
/// you need to ensure that the mouse events are passed to the dropdown.
120120
final ToggleBuilder toggleBuilder;
121121

122+
/// The color of the barrier that is shown when the dropdown is open.
123+
/// Defaults to `Colors.transparent`.
124+
/// This spans the entire screen.
125+
final Color barrierColor;
126+
122127
const GenericDropdown(
123128
{super.key,
124129
required this.contentBuilder,
@@ -127,6 +132,7 @@ final class GenericDropdown extends StatefulWidget {
127132
required this.toggleBuilder,
128133
this.closeOnOutsideTap = true,
129134
this.openOnRender = false,
135+
this.barrierColor = Colors.transparent,
130136
this.offset = Offset.zero});
131137

132138
@override
@@ -445,7 +451,7 @@ final class _GenericDropdownState extends State<GenericDropdown> {
445451
onTap: () => widget.closeOnOutsideTap ? _close() : null,
446452
child: Container(
447453
alignment: Alignment.topLeft,
448-
color: Colors.transparent,
454+
color: widget.barrierColor,
449455
child: Stack(
450456
children: [
451457
StatefulBuilder(builder: (context, setState) {

storybook/lib/main.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ Story _dropdown() => Story(
103103
description:
104104
'Whether the content is closed on an outside tap or only if the content calls close().',
105105
initial: true),
106+
barrierColor: context.knobs.options(
107+
label: 'Barrier Color',
108+
description: 'The color of the barrier behind the dropdown.',
109+
initial: Colors.transparent,
110+
options: [
111+
Option(label: 'Transparent', value: Colors.transparent),
112+
Option(label: 'Black', value: Colors.black.withOpacity(.5)),
113+
Option(label: 'Red', value: Colors.red.withOpacity(.5)),
114+
Option(label: 'Green', value: Colors.green.withOpacity(.5)),
115+
Option(label: 'Blue', value: Colors.blue.withOpacity(.5)),
116+
],
117+
),
106118
));
107119
});
108120

0 commit comments

Comments
 (0)