用扩展包裹InkWell不起作用

时间:2020-06-23 15:16:04

标签: flutter flutter-layout

我正在尝试完成我的应用程序,但是用Expanded包装的InkWell的onTap无效,这不是我调用的函数的问题,而是有关InkWell的问题。我该如何解决?

Expanded(
              child: InkWell(
                onTap: () {
                  setState(() {
                    reset();
                  });
                },
                child: MyCard(
                  height: MediaQuery.of(context).size.height * 0.07,
                  color: Color(0xfff4a261),
                  child: Text(
                    'Reset',
                    style: TextStyle(fontSize: 15),
                  ),
                ),
              ),
            ),

这是我创建的自定义类,位于上面的代码中

class MyCard extends StatelessWidget {
  final Color color;
  final Widget child;
 
  double height;
 
  MyCard({this.color, this.child, this.height});
 
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(4),
      child: Container(
        height: this.height,
        child: FlatButton(onPressed: () {}, child: this.child),
        decoration: BoxDecoration(
          color: this.color,
          borderRadius: BorderRadius.circular(5),
        ),
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

“材料小部件”是绘制墨well反应的地方。如果它们之间有任何不透明的图形(例如,使用Container,DecorationBox等进行绘制),则在这些小部件下绘制飞溅时将看不到飞溅。

您可以用材质小部件包装InkWell来解决此问题。

         Expanded(
          child: Material(
              child: InkWell(
                   onTap: () {
                   print("Clicked");
                     },
               child: MyCard(
               height: MediaQuery.of(context).size.height * 0.07,
               color: Color(0xfff4a261),
                  child: Text(
                    'Reset',
                       style: TextStyle(fontSize: 15),
                             ),
                          ),
                      ),
                    ) ,
                   );
相关问题