小编Ekr*_*gal的帖子

如果参数为空则使用默认值

如何才能更正确地编写下图中标记的代码块。我的目标是如果availableColors变量为 null ,则将默认值发送到参数。

代码块

showDialog<Color>(
  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);
}); …
Run Code Online (Sandbox Code Playgroud)

dart flutter

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

dart ×1

flutter ×1