How Disable all Widget

Use AbsorbPointer Widget

Today, I will introduce to a new widget in Flutter with which you can enable or disable any widget in Flutter.

If you wrap any widget in Flutter with the AbsorbPointer Widget, you can enable or disable that widget. That means if you wrap your whole UI in AbsorbPointer Widget, then you can control the user interaction on that UI by toggling the ‘absorbing’ property of AbsorbPointer Widget. When ‘absorbing‘ is true, the AbsorbPointer Widget absorbs all interaction in the widget’s child and in a way disabling it.

Let’s jump into the code.

The below code has three buttons, up on enabling the ‘absorbing‘ to false, all the buttons will be disabled at the same time and vice-versa.

Watch Video Tutorial

Below is the sample code

import 'package:flutter/material.dart';
 
class Tip2 extends StatefulWidget {
  Tip2() : super();
 
  final String title = "Tip Demo";
 
  @override
  Tip2State createState() => Tip2State();
}
 
class Tip2State extends State<Tip2> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: AbsorbPointer(
          absorbing: false,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              RaisedButton(
                child: Text("Click Me"),
                onPressed: () {},
              ),
              RaisedButton(
                child: Text("Click Me"),
                onPressed: () {},
              ),
              RaisedButton(
                child: Text("Click Me"),
                onPressed: () {},
              )
            ],
          ),
        ));
  }
}

Take a look at this line above

AbsorbPointer(
          absorbing: false,
          

false = button aktif

true = button nonaktif

https://www.coderzheaven.com/2019/01/20/flutter-tutorial-enable-disable-any-widget-android-and-ios/

Last updated