Skip to content

Commit 52d3f56

Browse files
prevent the dropdown from changing the value (#412)
1 parent a9c7dae commit 52d3f56

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/samples/show_legend/show_legend.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class _ShowLegendState extends State<ShowLegend> with SampleStateSupport {
9090
// Load the image and feature layers.
9191
await featureLayer.load();
9292
await imageLayer.load();
93+
if (!mounted) return;
94+
9395
// Create a list to store operational layers and populate it with image and feature layers.
9496
final operationalLayersList = <LayerContent>[
9597
...imageLayer.subLayerContents,
@@ -98,6 +100,8 @@ class _ShowLegendState extends State<ShowLegend> with SampleStateSupport {
98100

99101
// Create a list to store dropdown items.
100102
final legendsDropDown = <DropdownMenuEntry<LegendInfo>>[];
103+
// To use a DropdownMenu to present the legend, we disable each entry but use the enabled text style.
104+
final textTheme = Theme.of(context).textTheme;
101105
// Get the legend info for each layer and add it to the legends dropdown list.
102106
for (final layer in operationalLayersList) {
103107
// Get the legend info for the current layer.
@@ -107,10 +111,8 @@ class _ShowLegendState extends State<ShowLegend> with SampleStateSupport {
107111
DropdownMenuEntry(
108112
value: layerLegends.first,
109113
label: layer.name,
110-
labelWidget: Text(
111-
layer.name,
112-
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
113-
),
114+
enabled: false,
115+
labelWidget: Text(layer.name, style: textTheme.titleMedium),
114116
),
115117
);
116118

@@ -131,6 +133,7 @@ class _ShowLegendState extends State<ShowLegend> with SampleStateSupport {
131133
DropdownMenuEntry(
132134
value: legend,
133135
label: legend.name,
136+
enabled: false,
134137
labelWidget: Row(
135138
spacing: 8,
136139
children: [
@@ -140,7 +143,7 @@ class _ShowLegendState extends State<ShowLegend> with SampleStateSupport {
140143
else
141144
const SizedBox.shrink(),
142145
// Add the legend name to the dropdown list.
143-
Text(legend.name, style: const TextStyle(fontSize: 12)),
146+
Text(legend.name, style: textTheme.bodyMedium),
144147
],
145148
),
146149
),
-17.4 KB
Loading

0 commit comments

Comments
 (0)