【问题标题】:InkWell not working with a background imageInkWell 不使用背景图像
【发布时间】:2018-02-12 22:11:31
【问题描述】:

我正在构建我的第一个 Flutter 应用,我想创建一个简单的布局:一个背景图像和一个半透明的材质按钮。

我的 Widget 树非常简单,但 InkWell / Ripple 不可见。为什么我会有这种行为?

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Material(
      child: new Stack(
        children: <Widget>[
          new Container(
              decoration: new BoxDecoration(
                  image: new DecorationImage(
            image: new AssetImage("res/imgs/splashscreen_bg.png"),
            fit: BoxFit.cover,
          ))),
          new Center(
              child: new FlatButton(
                  onPressed: () {}, child: new Text("Hello world")))
        ],
      ),
    );
  }
}

没有背景图片,InkWell 可以工作。 我该怎么办?

谢谢

【问题讨论】:

标签: dart flutter


【解决方案1】:

经过一番研究,我发现了这个问题:https://github.com/flutter/flutter/issues/3782

如果我用这个新树更改 Widget 内容,它现在可以工作了:

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
      return new Stack(
        children: <Widget>[
          new Container(
              decoration: new BoxDecoration(
                  image: new DecorationImage(
            image: new AssetImage("res/imgs/splashscreen_bg.png"),
            fit: BoxFit.cover,
          ))),
          new Material(
            type: MaterialType.transparency,
          child: new FlatButton(...),
          )
        ],
    );
  }
}

【讨论】:

    【解决方案2】:

    最近有一个支持此功能的更新:https://github.com/flutter/flutter/pull/13900。我不确定它是否已经进入 Alpha 版,但它应该可以解决您的问题。

    【讨论】:

      猜你喜欢
      • 2021-07-21
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 2022-07-21
      • 2016-05-06
      • 2023-03-03
      相关资源
      最近更新 更多