flutter组件_AbsorbPointer

官方说明:A widget that absorbs pointers during hit testing.
翻译:一个在命中测试期间吸收指针的Widget。
作者释义:阻止子元素的点击事件 。

AbsorbPointer的定义

const AbsorbPointer({
  super.key,
  this.absorbing = true,
  this.ignoringSemantics,
  super.child,
});

属性:

属性名 属性值
absorbing 是否阻止子Widget的点击事件,默认为true(阻止)
ignoringSemantics 是否保持子Widget的语义信息,该特性在v3.8.0-12.0.pre之后已弃用。
child 子组件

实例:

import 'package:flutter/material.dart';

void main() => runApp(const AbsorbPointerApp());

class AbsorbPointerApp extends StatelessWidget {
  const AbsorbPointerApp({super.key});

  
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(title: const Text('AbsorbPointer Demo')),
        body: const Center(
          child: AbsorbPointerWidget(),
        ),
      ),
    );
  }
}

class AbsorbPointerWidget extends StatefulWidget {
  const AbsorbPointerWidget({super.key});

  
  State<AbsorbPointerWidget> createState() => _AbsorbPointerExampleState();
}

class _AbsorbPointerExampleState extends State<AbsorbPointerWidget> {
  bool isPrevent = true;

  
  Widget build(BuildContext context) {
    return Container(
      constraints: const BoxConstraints(
        minHeight: double.infinity
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Switch(
                value: isPrevent,
                onChanged:(value) => setState(() => isPrevent=value),
              ),
              const Text('是否阻止点击')
            ],
          ),
          SizedBox(
            width: 200.0,
            height: 100.0,
            child: AbsorbPointer(
              absorbing: isPrevent,
              child: ElevatedButton(
                onPressed: () {},
                child: const Text('Button'),
              ),
            ),
          )
        ],
      ),
    );
  }
}

在这里插入图片描述

如有错误请及时与作者联系~~非常感谢

相关推荐

  1. flutter Pageview

    2024-04-09 18:34:01       36 阅读
  2. flutter InheritedWidget

    2024-04-09 18:34:01       14 阅读
  3. flutter ThemeData

    2024-04-09 18:34:01       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-09 18:34:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-09 18:34:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-09 18:34:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-09 18:34:01       18 阅读

热门阅读

  1. NIO与BIO

    2024-04-09 18:34:01       10 阅读
  2. 蓝桥杯 算法训练 藏匿的刺客

    2024-04-09 18:34:01       11 阅读
  3. MySQL 常见和不常见的所有查询语句

    2024-04-09 18:34:01       16 阅读
  4. 自己总结的ICT云计算题库三

    2024-04-09 18:34:01       13 阅读
  5. 【Leetcode】【2024048】1544. Make The String Great

    2024-04-09 18:34:01       12 阅读
  6. react api:createContext

    2024-04-09 18:34:01       14 阅读