如何在内部敲击InkWell时如何防止对周围InkWell的波纹影响

问题描述 投票:0回答:2

假设我有这个小部件:

Card(
  child: InkWell(
    onTap: () {},
    child: Padding(
      padding: const EdgeInsets.all(28.0),
      child: RaisedButton(
        child: Text('Test'),
        onPressed: () {},
      ),
    ),
  ),
),

我仅在轻按Card时才禁用(防止显示)在InkWell / RaisedButton上的波纹效果,但在轻按Card时(即在按钮外部)显示)。有什么办法可以达到这种效果?

我认为一般性的问题可能是:当点击内部的InkWell时如何防止周围InkWell的波纹效应?如果您查看源代码,则可以看到RaisedButton具有MaterialInkWell会引起波纹的小部件。

Here is the full sample code

enter image description here

flutter dart flutter-layout
2个回答
3
投票

如果您想快速修改,请查看:

Container(
  width: 180,
  height: 120,
  child: Stack(
    children: <Widget>[
      Card(
        child: InkWell(
          onTap: () {},
        ),
      ),
      Center(
        child: RaisedButton(
          child: Text('Test'),
          onPressed: () {},
        ),
      )
    ],
  ),
)

enter image description here


0
投票

enter image description here

您可以处理onHighlightChanged方法中的逻辑;

Color _color;

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(),
    body: Center(
      child: Card(
        child: InkWell(
          splashColor: _color,
          highlightColor: _color,
          onTap: () {},
          child: Padding(
            padding: const EdgeInsets.all(28.0),
            child: RaisedButton(
              onHighlightChanged: (value) {
                if (value) {
                  setState(() => _color = Colors.white);
                } else {
                  Timer(Duration(milliseconds: 200), () {
                    setState(() => _color = null);
                  });
                }
              },
              child: Text('Test'),
              onPressed: () {},
            ),
          ),
        ),
      ),
    ),
  );
}
© www.soinside.com 2019 - 2024. All rights reserved.