toggles static method
Shows a list of on/off switches and gives back each name with its state.
switches maps each name to whether it starts on. Space flips the
highlighted one, right turns it on and left off.
final settings = Prompts.toggles('Settings', {
'Dark mode': true,
'Telemetry': false,
});
if (settings['Dark mode']!) enableDarkMode();
Implementation
static Map<String, bool> toggles(
String prompt,
Map<String, bool> switches, {
String Function(String name)? note,
}) {
final names = switches.keys.toList();
final on = PromptRunner.run(
TogglePrompt(
prompt,
names,
note: note,
on: {
for (var i = 0; i < names.length; i++)
if (switches[names[i]] ?? false) i,
},
),
).toSet();
return {for (final name in names) name: on.contains(name)};
}