是否可以将浮动操作按钮(FAB)的背景色设置为渐变而不是纯色?
我的按钮:
floatingActionButton: FloatingActionButton(
backgroundColor: const Color(0xFFFF006E),
child: const Icon(Icons.add, size: 40.0),
onPressed: () {
print('Start');
},
),
是否可以将浮动操作按钮(FAB)的背景色设置为渐变而不是纯色?
我的按钮:
floatingActionButton: FloatingActionButton(
backgroundColor: const Color(0xFFFF006E),
child: const Icon(Icons.add, size: 40.0),
onPressed: () {
print('Start');
},
),
floatingActionButton: FloatingActionButton(
child: Container(
width: 60,
height: 60,
child: Icon(
Icons.add,
size: 40,
),
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(colors: [Colors.red, Colors.blue])
),
),
onPressed: () {},
)
您可以使用带有所需渐变的Container
floatingActionButton: FloatingActionButton(
child: Container(
height: 60,
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle, // circular shape
gradient: LinearGradient(
colors: [
Colors.blueAccent,
Colors.red,
],
),
),
child: Icon(
Icons.add,
color: Colors.white,
),
),
)
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.yellow,
Colors.yellow.shade700,
],
),
shape: BoxShape.circle,
),
child: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.transparent,
elevation: 0,
child: Icon(Icons.home)
),
),
希望这样可以做到....
FloatingActionButton(
onPressed: () {},
child: Container(
height: 60,
width: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
Colors.teal,
Colors.tealAcent
],
),
),
child: Icon(
Icons.add,
color: Colors.white,
),
),
)