Reputation: 29
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, ), ), ), ); }
i want to show gradient if gradient is passed to the function or if color is passed color is shown. i have implemented this, but it's expecting an identifier. don't know how to put this and where to
Upvotes: 2
Views: 462
Reputation: 17950
Try this:
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,
),
),
),
);
}
In non-nullable app do this:
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,
),
),
),
);
}
Upvotes: 2