加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

颤动 – InkWell没有出现涟漪效应

发布时间:2020-12-14 14:55:18 所属栏目:百科 来源:网络整理
导读:点击容器会触发onTap处理程序,但不会显示任何墨水飞溅效果. class _MyHomePageState extends StateMyHomePage { @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text(widget.title),),body: new Cent
点击容器会触发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放入容器内,但是徒劳无功.

解决方法

我认为在容器中添加颜色可以覆盖墨水效果

https://docs.flutter.io/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,color: Colors.transparent,

只需点击中间的方块.

编辑:我找到了bug报告. 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 which 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.

On 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读