Flutter Tutorial – Enable/Disable Any Widget – Android and iOS.

By | January 20, 2019

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,
...

 
Please leave your valuable comments below.

Thanks.

 

3 thoughts on “Flutter Tutorial – Enable/Disable Any Widget – Android and iOS.

  1. Monish Sinthala

    I am a developer and more importantly, I am a fresher and I find this blog too good and tutorials are excellent. It’s very important that developers in each and every Flutter app development company see this. Anyways, will share it with my peers. Thank you.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *