我认为将颜色添加到容器中会掩盖墨水效果。
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,
),
),
只需点击中间的正方形。
编辑:我找到了错误报告。https://github.com/flutter/flutter/issues/3782
实际上,这是预期的结果,但我们应该更新文档以使其更清晰。
发生的情况是,Material规范指出,飞溅实际上是墨水在材料上。因此,当我们飞溅时,我们实际上是让Material widget执行飞溅操作。如果您在Material上面有其他东西,我们会在其下飞溅,您看不到它。
我想添加一个“MaterialImage”小部件,将其图像概念地打印到Material中,这样飞溅就可以覆盖图像。我们可以使用类似于装饰的MaterialDecoration来处理装饰。或者我们可以让Material本身采用装饰。现在它采用颜色,但我们可以扩展它以采用整个装饰。不清楚具有渐变的材料是否真正符合材料规范,因此我不确定我们是否应该这样做。
在短期内,如果您只需要解决问题,您可以在容器顶部放置一个Material,将材料设置为使用“透明”类型,然后将墨水井放在其中。
- hixie
更新: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类文档中复制了代码。
https://github.com/Hixie/flutter/blob/1f6531984984f52328e66c0cd500a8d517964564/packages/flutter/test/material/ink_paint_test.dart
https://github.com/flutter/flutter/pull/13900
https://api.flutter.dev/flutter/material/Ink-class.html