我想將漸變顏色應用于影像,我嘗試將影像包裝在容器中并在裝飾中給出漸變。但是顏色適用于整個容器,包括影像背景。但這不是我所期望的,
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color.fromRGBO(103, 7, 224, 1),
Color.fromRGBO(255, 97, 220, 1)
],
)),
child: SvgPicture.asset(
AssetImages.REWARDS,
height: 28,
width: 20,
),
)
請幫忙..
`
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color.fromRGBO(103, 7, 224, 1),
Color.fromRGBO(255, 97, 220, 1)
],
)),
child: SvgPicture.asset(
AssetImages.REWARDS,
height: 28,
width: 20,
),
)
`
我期待這樣的事情

uj5u.com熱心網友回復:
我為漸變圖示創建了一個輔助類:
class GradientIcon extends StatelessWidget {
GradientIcon(
this.icon,
this.size,
);
Color buttonbBlue2 =Color(0xFF00B4F8); //colors you want
Color buttonbBlue3 =Color(0xFF00A1EF);
final IconData icon;
final double size;
final Gradient gradient = LinearGradient(
begin: Alignment.bottomLeft,
end: Alignment.topRight,
stops: [ 0.1, 0.7],
colors: <Color>[
buttonbBlue2 ,
buttonbBlue3
],
);;
@override
Widget build(BuildContext context) {
return ShaderMask(
child: SizedBox(
width: size * 1.2,
height: size * 1.2,
child: Icon(
icon,
size: size,
color: Colors.white,
),
),
shaderCallback: (Rect bounds) {
final Rect rect = Rect.fromLTRB(0, 0, size, size);
return gradient.createShader(rect);
},
);
}
}
用法 :
GestureDetector(
onTap: () {
_openPopup(context,
"Update Mobile ", "Mobile*");
},
child: GradientIcon(
Icons.edit,
20.0,
)),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/526460.html
標籤:扑镖颜色容器坡度
