Mastering Development

using the default value if the parameter is null

How can I write the code block marked in the picture below more properly. My goal is to send the default value to the parameter if the availableColors variable is null.

Code Block

  context: context,
  builder: (BuildContext context) {
    return OrientationBuilder(
      builder: (context, orientation) {
        return ResponsiveDialog(
          context: context,
          title: title,
          headerColor: headerColor,
          headerTextColor: headerTextColor,
          backgroundColor: backgroundColor,
          buttonTextColor: buttonTextColor,
          child: availableColors == null ? BlockPicker(
            pickerColor: selectedColor,
            onColorChanged: (color) => selectedColor = color,
          ): BlockPicker(
            pickerColor: selectedColor,
            availableColors: availableColors,
            onColorChanged: (color) => selectedColor = color,
          okPressed: () => Navigator.of(context).pop(selectedColor),
).then((selection) {
  if (onChanged != null && selection != null) onChanged(selection);

I can’t change BlockPicker. It comes from an external library.

class BlockPicker extends StatefulWidget {
  const BlockPicker({
    @required this.pickerColor,
    @required this.onColorChanged,
    this.availableColors = _defaultColors,
    this.layoutBuilder = defaultLayoutBuilder,
    this.itemBuilder = defaultItemBuilder,

Leave a Reply

Your email address will not be published. Required fields are marked *