BranchDev
BranchDev

Reputation: 154

How to disable Inkwell image button in flutter

I would like to make the inkwell image button to be disabled. I can disable onTap event, but can't make gray like disabled button. I tried with adding this code

decoration: new BoxDecoration(color:Colors.grey.withOpacity(0.6)),

But it doesn't work as I want.

My code:

 child: Container(
              decoration:
                  new BoxDecoration(color: Colors.grey.withOpacity(0.6)),
              child: Material(
                //elevation: 4.0,
                clipBehavior: Clip.none,
                color: Colors.black,
                child: Stack(
                  alignment: Alignment.center,
                  fit: StackFit.passthrough,
                  children: [
                    Ink.image(
                      image: AssetImage(ihaveheard_imagepath),
                      fit: BoxFit.cover,
                      width: MediaQuery.of(context).size.width / 4 * 3,
                      height: MediaQuery.of(context).size.width / 6,
                      child: InkWell(onTap: () {}),
                    ),
                    Align(
                      alignment: Alignment.center,
                      child: Padding(
                        padding: EdgeInsets.all(8.0),
                        child: InkWell(
                          child: Text(
                            LocaleKeys.ihaveheard,
                            style: TextStyle(
                                fontSize:
                                    MediaQuery.of(context).size.width / 30,
                                color: Colors.white),
                          ).tr(),
                          onTap: () {
                            ihaveheard_imagepath =
                                "assets/images/greenbutton.png";

                            setState(() {});
                          },
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ),

Upvotes: 1

Views: 1935

Answers (2)

BranchDev
BranchDev

Reputation: 154

child:
 IgnorePointer(
              ignoring: disableBtn, //true or false

              child: Container(
                foregroundDecoration: disableBtn 
                    ? BoxDecoration( //this can make disabled effect
                        color: Colors.grey,
                        backgroundBlendMode: BlendMode.lighten)
                    : null,
               child: ...
                 

Upvotes: 1

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63739

You can use IgnorePointer as parent widget to prevent tab event.

IgnorePointer(
  ignoring: disableBtn, //true, false
  child: yourWidget()

You can pass null to decoration to show default based on tappable state

Container(
 decoration: disableBtn? BoxDecoration(...): null,
 .....
)

Upvotes: 0

Related Questions