AbsorbPointer
的定义
const AbsorbPointer({
super.key,
this.absorbing = true,
this.ignoringSemantics,
super.child,
});
属性:
属性名 | 属性值 |
---|---|
absorbing | 是否阻止子Widget的点击事件,默认为true(阻止) |
是否保持子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'),
),
),
)
],
),
);
}
}