flutter - 如何在 Flutter 中将 Container 上的涟漪效果显示为 IconButton 子项?
问题描述
标准 IconButton 不会对孩子产生任何连锁反应:
IconButton(
icon: Container(color: Colors.red,),
onPressed: () {},
)
所以我尝试用 Stack 修复它:
class MyIconButton extends StatelessWidget {
const MyIconButton({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: 100,
width: 100,
child: Stack(
fit: StackFit.loose,
children: [
Positioned.fill(
child: Container(
width: 40,
height: 40,
color: Colors.deepPurple,
),
),
Positioned.fill(
child: Material(
type: MaterialType.transparency,
shape: const CircleBorder(),
child: IconButton(
splashRadius: 50,
icon: Container(),
onPressed: () {
},
),
),
)
],
),
);
}
}
但是这个小部件需要定义容器的大小,当我定义该大小时,我无法在该容器之外显示涟漪效应。我愿意接受建议。
解决方案
Container
用小部件替换您的Ink
。
IconButton(
onPressed: () {},
icon: Ink(color: Colors.red),
)
墨水:
用于在 Material 小部件上绘制图像和其他装饰的便捷小部件,以便 InkWell 和 InkResponse 飞溅将呈现在它们之上。
推荐阅读
- sqlalchemy - 为特定行更新 SQL 中的记录
- python - AttributeError:“QuantumCircuit”对象没有属性“config”
- keycloak - 管理 keycloak 资源
- angular - 使用 ngFor 和角顶点图的多个图表
- date - Power BI:在 DAX 中按 YearMonth 排序数据
- java - 在秋千图标的顶部绘画?
- python - 将一些列转换为浮点数
- javascript - 在烧瓶本地主机服务器中使用 javascript 位置对象时遇到问题
- javascript - “TypeError:this.context._getProps 不是函数”尝试通过 props.children 传递元素时
- ios - 如何在swift 5中解析xml并将xml数据填充到UITableview中?