首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Flutter Container时,一切正常,但没有涟漪效果-但Ink超出了它的父级

问使用Flutter Container时,一切正常,但没有涟漪效果-但Ink超出了它的父级
EN

Stack Overflow用户
提问于 2021-10-20 11:34:36
回答 1查看 165关注 0票数 0

我想提供几个按钮内的一个单一的滚动视图

​

​

​

代码语言:javascript
复制
Column(
    children: < Widget > [
      SizedBox(height: constraints.maxHeight / 8.0),
      AnimationConfiguration.staggeredList(
        position: 1,
        duration: const Duration(milliseconds: 2000),
          child: SlideAnimation(
            verticalOffset: constraints.maxHeight / 10,
            child: FadeInAnimation(
              child: Image.asset('images/mylive.png'),
            ),
          ),
      ),
      Flexible(
        child: Padding(
          padding: EdgeInsets.fromLTRB(
            50, 20, 50, constraints.maxHeight / 7),
          child: SingleChildScrollView(
            child: Padding(
              padding: const EdgeInsets.all(10),
                child: Wrap(
                  spacing: 25,
                  runSpacing: 25,
                  children: const < Widget > [
                    ButtonCard(
                      name: "My News",
                      imgpath: "open-email.png",
                      count: 0),

​

下面是ButtonCard的构建方法:

​

代码语言:javascript
复制
 Widget build(BuildContext context) {
    final double width = MediaQuery.of(context).size.width;
    final double height = MediaQuery.of(context).size.height;
    return InkWell(
      onTap: () {},
      child: Container(    <<--->>     Ink(
        padding: const EdgeInsets.all(10),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
          color: Colors.white,
          boxShadow: const [
            BoxShadow(
              color: Colors.black38,
              offset: Offset(0, 2),
              blurRadius: 7,
            ),
          ],
        ),
        child: Column(
          children: [
            Stack(
              children: [
                Image.asset(
                  "assets/images/$imgpath",
                  width: 60,
                ),
              ],
            ),
            Padding(
              padding: const EdgeInsets.only(top: 8.0),
              child: Text(
                name,
                style: const TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 15,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

​

当我在ButtonCard中使用容器时,一切正常,但是InkWell没有显示出涟漪效果(因为BoxDecation颜色设置)

这将产生以下正确的滚动视图:

​

但是当我将Container改为Ink时,我得到了我想要的美丽的涟漪效果。但是在收集过程中发生了以下错误:

​

​

正如您所看到的,Ink和它的盒子装饰在父级边框上绘制。这是Ink中的一个bug吗?或者有人知道问题出在哪里吗?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2021-11-17 03:22:12

在一般情况下:

用Inkwell

  • Wrap包装
  1. 用Inkwell
  2. Wrap包装所需颜色的Inkwell用Material
  3. Set颜色到作为transparent

的Container

有了以上的设置,你就可以用油墨产生涟漪效果。但是当你有渐变颜色时,很难实现。

参考:https://flutteragency.com/inkwell-not-showing-ripple-effect-in-flutter/

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69645233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档