variableChooser function
Implementation
Widget variableChooser(
String label,
List<String> inputs,
String selected,
WidgetRef ref,
StateProvider stateProvider, {
// Add this parameter to control if the dropdown is enabled.
required bool enabled,
required String tooltip,
// Add a callback for onChanged to handle custom logic.
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';
if (onChanged != null) {
// Call the custom callback if provided.
onChanged(value);
}
}
},
// Add a custom style for when it's disabled.
textStyle: TextStyle(
// Set grey when disabled.
color: enabled ? Colors.black : Colors.grey,
),
),
);
}