InkWell无法使用背景图像

时间:2018-02-12 22:11:32

标签: dart flutter

我正在构建我的第一个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正在工作。 我该怎么办?

由于

2 个答案:

答案 0 :(得分:2)

经过一些研究后,我发现了这个问题: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(...),
          )
        ],
    );
  }
}

答案 1 :(得分:1)

最近有一项更新支持此项:https://github.com/flutter/flutter/pull/13900。我不确定它是否已经成为了阿尔法,但它应该解决你的问题。