HapticPatternPicker constructor
HapticPatternPicker({
- Key? key,
- required List<
HapticPatternOption> options, - required String? selectedId,
- required ValueChanged<
String?> onSelect, - required ValueChanged<
HapticPattern> onPreview, - bool hapticsEnabled = true,
- bool busy = false,
- String previewLabel = 'Preview',
- String busyLabel = 'Playing',
- String disabledLabel = 'Haptics off',
- String semanticLabel = 'Haptic pattern',
Implementation
HapticPatternPicker({
super.key,
required this.options,
required this.selectedId,
required this.onSelect,
required this.onPreview,
this.hapticsEnabled = true,
this.busy = false,
this.previewLabel = 'Preview',
this.busyLabel = 'Playing',
this.disabledLabel = 'Haptics off',
this.semanticLabel = 'Haptic pattern',
}) {
if (options.isEmpty || options.length > 3) {
throw ArgumentError.value(options.length, 'options', 'must be in 1..3');
}
final ids = <String>{};
for (final option in options) {
if (option.id.trim().isEmpty) {
throw ArgumentError.value(option.id, 'options', 'id must not be blank');
}
if (!ids.add(option.id)) {
throw ArgumentError.value(option.id, 'options', 'duplicate id');
}
if (option.label.trim().isEmpty) {
throw ArgumentError.value(
option.label,
'options',
'label must not be blank',
);
}
}
if (selectedId != null && !ids.contains(selectedId)) {
throw ArgumentError.value(
selectedId,
'selectedId',
'must be null or an option id',
);
}
for (final (name, value) in [
('previewLabel', previewLabel),
('busyLabel', busyLabel),
('disabledLabel', disabledLabel),
('semanticLabel', semanticLabel),
]) {
if (value.trim().isEmpty) {
throw ArgumentError.value(value, name, 'must not be blank');
}
}
}