variableChooser function
Implementation
Widget variableChooser(
String label,
List<String> inputs,
String selected,
WidgetRef ref,
StateProvider stateProvider, {
// Add a parameter to control if the dropdown is enabled.
required bool enabled,
required String tooltip,
// Add a callback for onChanged to handle custom logic.
//
// 20250910 gjw I removed this being an optional parameter to avoid dart code
// metrics identiying unnecessary nullable since all calls provide a
// function. But to do so I need to provide a default, which in this case does
// nothing.
required Function(String?) onChanged,
}) {
return MarkdownTooltip(
message: tooltip,
child: DropdownMenu(
label: Text(label),
width: 200,
initialSelection: selected,
dropdownMenuEntries: inputs.map((s) {
return DropdownMenuEntry(value: s, label: s);
}).toList(),
// Use the enabled parameter to control the dropdown state.
enabled: enabled,
onSelected: (String? value) {
if (enabled) {
ref.read(stateProvider.notifier).state = value ?? 'IMPOSSIBLE';
onChanged(value);
}
},
// Add a custom style for when it's disabled.
textStyle: TextStyle(
// Set grey when disabled.
color: enabled ? Colors.black : Colors.grey,
),
),
);
}