flutter - Flutter:当 InkWell() 的子元素是容器时如何修复 Tap 效果
问题描述
我试图在它的孩子是容器时触发 InkWell 水龙头效果,但它不起作用。所以显然问题是如何在点击 InkWell 时显示一些水龙头效果。这是代码:
InkWell(
onTap: () {},
child: Container(
decoration: BoxDecoration(
color: isAvailable!
? Color.fromRGBO(0, 118, 0, 1)
: Color.fromRGBO(114, 114, 114, 1),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(15),
bottomRight: Radius.circular(15),
),
),
width: (MediaQuery
.of(context)
.size
.width - 60) / 2,
height: 50,
child: Center(
child: Text(
'Request',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
),
)
解决方案
当您点击时会出现墨迹动画,但由于它位于容器后面,所以它没有显示,所以我通过删除容器对您的代码进行了一些修改,并引入了 Ink 小部件
解决方案 1:
InkWell(
onTap: () {},
child: Ink(
width: (MediaQuery.of(context).size.width - 60) / 2,
height: 50,
decoration: BoxDecoration(
color: isAvailable
? Color.fromRGBO(0, 118, 0, 1)
: Color.fromRGBO(114, 114, 114, 1),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(15),
bottomRight: Radius.circular(15),
),
),
child: Center(
child: Text(
'Request',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
),
);
解决方案 2:通过重新排序小部件
Container(
decoration: BoxDecoration(
color: isAvailable
? Color.fromRGBO(0, 118, 0, 1)
: Color.fromRGBO(114, 114, 114, 1),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(15),
bottomRight: Radius.circular(15),
),
),
width: (MediaQuery.of(context).size.width - 60) / 2,
height: 50,
child: Material(
child: InkWell(
onTap: () {},
child: Center(
child: Text(
'Request',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
),
color: Colors.transparent,
),
),
推荐阅读
- c++ - Qt 中是否有签名的“sizeof”替代方案
- windows - 将文件夹结构和子目录/文件导出为文本
- javascript - 在javascript中获取具有相同ID的不同值
- sql - 随时间更新列
- javascript - select2 在所选选项上绘制图像和文本
- python - 无法在 Keras 中加载克隆模型
- java - 无法通过 SSH 使用 XForwarding 运行 armitage(可能是 java 问题)
- scala - 隐含的用途是什么以及如何在scala中使用它们?
- docker - informix docker 映像中缺少 Dbimport 实用程序?
- python - 创建多处理数组时出现分段错误