AbsorbPointer Widget in Flutter To Disable onPressed on All Child Tree

As we all know in flutter most widgets offer us to set click event on them and we can also disable them by passing Null. In Raised Button widget we can pass null to onPressed() event to make it disable. Same as in ListView widget we can set NeverScrollableScrollPhysics() event to disable scrolling in Listview widget. But what if we have ton of widgets and want to disable them on single event. Here comes the AbsorbPointer widget, AbsorbPointer widget disables click event on all the Child tree and make them un-pressable. So in this tutorial we would learn about AbsorbPointer Widget in Flutter in Android iOS with explained example.

Contents in this project AbsorbPointer Widget in Flutter Android iOS Example:

1. The first step is open your project’s main.dart file and import material.dart package.

2. Creating void main runApp() method and here we would call our main MyApp class.

3. Creating our main MyApp extends StatelessWidget class.  This is our Root class.

4. Creating a sample function named as messagePrint(). We would call this function on Raised button onPressed event. Inside this function we are simply printing a message on terminal screen.

5. Creating Widget Build area -> Material App -> Scaffold widget -> Safe Area widget -> Center Widget.

6. Creating AbsorbPointer widget as Parent then create a Column widget as its child. Now we would make 3 RaisedButton widget in Column widget.

  • absorbing : Used to set Whether this widget absorbs pointers during hit testing. In simple manner to enable and disable Click, OnPressed event given child tree.
  • ignoringSemantics : Used to set Whether the semantics of this render object is ignored when compiling the semantics tree.

7. Complete source code for main.dart file:

Screenshot:

AbsorbPointer Widget in Flutter To Disable onPressed on All Child Tree

Leave a Reply

Your email address will not be published.