问题
I don't want to add any plugins just for one icon in my app but I need two tone because the background color will vary and I don't know when it will be dark and when it will be light.
I mean icons like these - https://material.io/tools/icons/?style=twotone where icons have border of different color.
回答1:
If i understood your Question Correctly, here is an example of two Color Tone Icon
& Text
.
You can play around with Color, radius & other Parameters to fit your Needs.
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ShaderMask(
blendMode: BlendMode.srcATop,
shaderCallback: (Rect bounds) {
return RadialGradient(
center: Alignment.topLeft,
radius: 1.0,
colors: <Color>[Colors.red, Colors.cyanAccent],
tileMode: TileMode.mirror,
).createShader(bounds);
},
child: Text(
'Two Tone Color Icon & Text!',
style: TextStyle(fontSize: 22.0),
),
),
SizedBox(
height: 10.0,
),
ShaderMask(
blendMode: BlendMode.srcATop,
shaderCallback: (Rect bounds) {
return RadialGradient(
center: Alignment.center,
radius: 1.0,
colors: <Color>[
Colors.greenAccent[200],
Colors.blueAccent[200]
],
tileMode: TileMode.repeated,
).createShader(bounds);
},
child: Icon(
Icons.dashboard,
size: 32.0,
),
),
],
),
),
Output:
来源:https://stackoverflow.com/questions/54087139/how-can-i-add-2-tone-icons-without-using-any-plugin