容纳一个子组件,可以通过指定ignoring属性,来决定孩子是否忽略手势事件,其本身接受事件。

相关组件

GestureDetector InkResponse InkWell IgnorePointer

AbsorbPointer基本使用

  1. <br />【child】 : 孩子组件 【Widget】<br />【absorbing】 : 是否吸收事件 【bool】<br />如下,Switch选中时absorbing为true,按钮事件将被吸收,无法点击。<br />![185.gif](https://cdn.nlark.com/yuque/0/2020/gif/326147/1589507308889-438d773a-4f5b-46b1-9f35-e1e337b52ea7.gif#align=left&display=inline&height=502&margin=%5Bobject%20Object%5D&name=185.gif&originHeight=502&originWidth=406&size=1931538&status=done&style=none&width=406)
import 'package:flutter/material.dart';
class CustomAbsorbPointer extends StatefulWidget {
  @override
  _CustomAbsorbPointerState createState() => _CustomAbsorbPointerState();
}

class _CustomAbsorbPointerState extends State<CustomAbsorbPointer> {
  bool _absorbing = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Wrap(
        crossAxisAlignment: WrapCrossAlignment.center,
        children: <Widget>[
          GestureDetector(
            onTap: (){
              print('AbsorbPointer');
            },
            child: AbsorbPointer(
              absorbing: _absorbing,
              child: _buildButton(),
            ),
          ),
          _buildSwitch(),
          Text(!_absorbing ? '允许点击' : '事件已被吸收')
        ],
      ),
    );
  }

  Widget _buildButton() => RaisedButton(
      color: Theme.of(context).primaryColor,
      child: Text(
        'To About',
        style: TextStyle(color: Colors.white),
      ),
      onPressed: () => Navigator.of(context).pushNamed('AboutMePage'));

  _buildSwitch() => Switch(
      value: _absorbing,
      onChanged: (v) {
        setState(() {
          _absorbing = v;
        });
      });
}