How do I disable a Button in Flutter?

后端 未结 8 2142
不思量自难忘°
不思量自难忘° 2020-12-04 17:19

I\'m just starting to get the hang of Flutter, but I\'m having trouble figuring out how to set the enabled state of a button.

From the docs, it says to set onP

相关标签:
8条回答
  • 2020-12-04 17:50

    According to the docs:

    "If the onPressed callback is null, then the button will be disabled and by default will resemble a flat button in the disabledColor."

    https://docs.flutter.io/flutter/material/RaisedButton-class.html

    So, you might do something like this:

        RaisedButton(
          onPressed: calculateWhetherDisabledReturnsBool() ? null : () => whatToDoOnPressed,
          child: Text('Button text')
        );
    
    0 讨论(0)
  • 2020-12-04 18:01

    You can also use the AbsorbPointer, and you can use it in the following way:

    AbsorbPointer(
          absorbing: true, // by default is true
          child: RaisedButton(
            onPressed: (){
              print('pending to implement onPressed function');
            },
            child: Text("Button Click!!!"),
          ),
        ),
    

    If you want to know more about this widget, you can check the following link Flutter Docs

    0 讨论(0)
提交回复
热议问题