- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
点击容器会触发 onTap()
处理程序,但不会显示任何墨水飞溅效果。
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new InkWell(
onTap: (){print("tapped");},
child: new Container(
width: 100.0,
height: 100.0,
color: Colors.orange,
),
),
),
);
}
}
我也尝试将 InkWell
放入 Container
中,但没有成功。
最佳答案
我认为给容器添加颜色会覆盖墨水效果
https://api.flutter.dev/flutter/material/InkWell/InkWell.html
这段代码似乎可以工作
body: new Center(
child: new Container(
child: new Material(
child: new InkWell(
onTap: (){print("tapped");},
child: new Container(
width: 100.0,
height: 100.0,
),
),
color: Colors.transparent,
),
color: Colors.orange,
),
),
只需点击中间的方 block 。
编辑:我找到了错误报告。 https://github.com/flutter/flutter/issues/3782
This is actually as expected, though we should update the docs to make it clearer.
What's going on is that the Material spec says that the splashes are actually ink on the Material. So when we splash, what we do is we literally have the Material widget do the splash. If you have something on top of the Material, we splash under it, and you can't see it.
I have wanted to add a "MaterialImage" widget that conceptually prints its image into the Material as well so that then the splashes would be over the image. We could have a MaterialDecoration which does something similar for a Decoration. Or we could have Material itself take a decoration. Right now it takes a color, but we could extend that to taking a whole decoration. It's not clear whether it's really material-spec-compatible to have a material with a gradient, though, so I'm not sure whether we should do that.
In the short run, if you just need a workaround, you can put a Material on top of the container, with the material set to use the "transparency" type, and then put the ink well inside that.
--喜喜
更新:Hixie 去年合并了一个新的 Ink 解决方案。 Ink 提供了一种在图像上飞溅的便捷方式。
testWidgets('Does the Ink widget render anything', (WidgetTester tester) async {
await tester.pumpWidget(
new Material(
child: new Center(
child: new Ink(
color: Colors.blue,
width: 200.0,
height: 200.0,
child: new InkWell(
splashColor: Colors.green,
onTap: () { },
),
),
),
),
);
Material(
color: Colors.grey[800],
child: Center(
child: Ink.image(
image: AssetImage('cat.jpeg'),
fit: BoxFit.cover,
width: 300.0,
height: 200.0,
child: InkWell(
onTap: () { /* ... */ },
child: Align(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text('KITTEN', style: TextStyle(fontWeight: FontWeight.w900, color: Colors.white)),
),
)
),
),
),
)
请注意:我没有测试新的 Ink Widget。我处理了 ink_paint_test.dart 和 Ink 类文档中的代码
关于flutter - InkWell 没有显示涟漪效应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45424621/
假设我有这个小部件: Card( child: InkWell( onTap: () {}, child: Padding( padding: const EdgeIn
body: InkWell( onTap: (){ print("optap"); }, child: Container(
我使用 Inkwell 来添加一些效果,但是这个小部件也监听 onTap 事件。我不想要这个;我只希望它监听 onDoubleTap 事件,然后通过 Accent Widget(一个 TabBar,默
我正在构建我的第一个 Flutter 应用程序,我想创建一个简单的布局:一个背景图像和一个半透明的 Material 按钮。 我的 Widget 树非常简单,但是 InkWell/Ripple 不可见
点击容器会触发 onTap() 处理程序,但不会显示任何墨水飞溅效果。 class _MyHomePageState extends State { @override Widget buil
在做了一些研究之后,我尝试用 InkWell 包裹 ListTiles获取 onTap涟漪效应,但它似乎不起作用。这就是我所拥有的: return AnimationLimiter( ch
我是 Flutter 开发的新手,在我学习的过程中,我遇到了响应触摸的 Ink 小部件,同时还显示了一些动画飞溅效果。 但是,有两种几乎相似的小部件类型,即 InkWell 和 InkResponse
假设你有几个嵌套的 InkResponse ,如果你点击内部的,所有的父元素实际上都会触发飞溅效果,即使它们会在点击区域中为正确的点击小部件松动。效果将是这样的: 如何防止此类行为?如何显示飞溅 只有
我有一个问题。我有一个 InkWell 小部件,但我不希望它有启动画面动画。有没有办法摆脱这个动画? 最佳答案 如果您不关心启动动画,请不要使用 InkWell。该小部件仅为此而存在。 而是使用 Ge
我正在用 flutter 编写我的第一个应用程序,并遇到了 InkWell 在被点击时无法检测到的问题。这是一个比我能找到的例子更复杂的结构。我写了以下函数: class ChatOverviewEl
我在 Flutter 中复制普通设置菜单时遇到问题。我正在使用 InkWell 来尝试创建通常在您点击设置选项时出现的飞溅效果。问题是飞溅效果与正常情况相比显得太快了。基本上,我只是想放慢 InkWe
我是 flutter 的新手,我的第一步已经导致了我无法通过自己或搜索此网站解决的错误.. 我想创建一个按钮,但据我所知得到了缺少方向性的异常(exception)情况。唯一需要 textDirect
我正在尝试在卡片小部件上实现和 inkWell 包装,但它根本不起作用。我将点击保留为空,因为该类需要 3 个参数,我稍后会填充这些参数以生成多张卡片。我看不到阻止 InkWell 产生涟漪的原因,因
我有一个这样的小部件测试,我可以用 actionKey 找到小部件,但敲击测试失败且 tapped tester.tap(...) 之后的值为假,我的测试有什么问题? testWidgets('som
我是 flutter 的新手,我有一个计数器按钮,我想防止它被多次触摸。 Tap 函数在 Inkwell 组件下定义 (onTap: () => counterBloc.doCount(context
在处理应用程序时,我们有一个实例,我们希望卡片上有一个墨水池以及卡片上的一个按钮(也有一个墨水池)。但是,我一直无法确定一种方法来分离手势,以便只调用用户点击下的墨水瓶。就像今天一样,水龙头似乎“流过
我在 Row 中添加 InkWell 作为 Widget,但它抛出了一个错误: flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞══════════
我在 FloatingActionButton 中有一个 PopupMenuButton。但它的 InkWell 不是圆形的,而是标准的方形。我怎样才能做到这一点? 最佳答案 使用 InkWell 的
我是 Flutter 的新手,了解了 InkWell 和 GestureDetector。在我看来,它们几乎是一样的。官方文档没有提供它们之间的任何深入比较。 InkWell 和 GestureDet
我想使用 GestureDetector,因为它有 onTapDown 回调,但也有不错的 InkWell 飞溅效果。 这两个可以一起使用吗? 最佳答案 如果你想无条件地处理没有gesture dis
我是一名优秀的程序员,十分优秀!