HapticPatternPicker constructor

HapticPatternPicker({
  1. Key? key,
  2. required List<HapticPatternOption> options,
  3. required String? selectedId,
  4. required ValueChanged<String?> onSelect,
  5. required ValueChanged<HapticPattern> onPreview,
  6. bool hapticsEnabled = true,
  7. bool busy = false,
  8. String previewLabel = 'Preview',
  9. String busyLabel = 'Playing',
  10. String disabledLabel = 'Haptics off',
  11. 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');
    }
  }
}