InkWell buildAppBarActionItem({ Gradient gradient, String icon, double width = 36, double height = 36, double radius = 12, Color color, Function onpressed, double opacity = 1, }) { return InkWell( onTap: onpressed, child: Container( width: width, height: height, decoration: BoxDecoration( borderRadius: BorderRadius.all( Radius.circular(radius), ), **if(color){ color: color.withOpacity(opacity) } else{ gradient: StyleBtn.buildLinearGradient(begin: Alignment.topLeft, eng: Alignment.topRight) }** // color? color: color.withOpacity(opacity) : gradient: StyleBtn.buildLinearGradient(begin: Alignment.topLeft, eng: Alignment.topRight), ), child: Center( child: ImageIcon( AssetImage("assets/icon/${icon}"), size: 16.0, color: MyTheme.white, ), ), ), ); }
如果渐变传递给函数或者颜色传递,我想显示渐变颜色。我已经实现了这个,但它需要一个标识符。不知道如何放置它以及放置在哪里
最佳答案
试试这个:
InkWell buildAppBarActionItem({
Gradient? gradient,
String? icon,
double width = 36,
double height = 36,
double radius = 12,
Color? color,
Function()? onpressed,
double opacity = 1,
}) {
return InkWell(
onTap: onpressed,
child: Container(
width: width,
height: height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(radius),
),
color: color != null? color.withOpacity(opacity) : null,
gradient: color == null? StyleBtn.buildLinearGradient(begin: Alignment.topLeft, eng: Alignment.topRight) : null,
),
child: Center(
child: ImageIcon(
AssetImage("assets/icon/${icon}"),
size: 16.0,
color: MyTheme.white,
),
),
),
);
}
在不可为 null 的应用程序中执行以下操作:
InkWell buildAppBarActionItem({
Gradient gradient,
String icon,
double width = 36,
double height = 36,
double radius = 12,
Color color,
Function() onpressed,
double opacity = 1,
}) {
return InkWell(
onTap: onpressed,
child: Container(
width: width,
height: height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(radius),
),
color: color != null? color.withOpacity(opacity) : null,
gradient: color == null? StyleBtn.buildLinearGradient(begin: Alignment.topLeft, eng: Alignment.topRight) : null,
),
child: Center(
child: ImageIcon(
AssetImage("assets/icon/${icon}"),
size: 16.0,
color: MyTheme.white,
),
),
),
);
}
关于flutter - 如果传递了渐变,则框装饰中的渐变或颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73618268/