I am trying to disable a TextButton that I've coded as follows:
// Setup new game button
final TextButton newGameButton = new TextButton("New Game", style);
newGameButton.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
Tyr.getInstance().setScreen(new GameScreen());
AudioHelper.stopMusic();
return true;
}
});
table.add(newGameButton).spaceBottom(BUTTON_SPACE);
table.row();
However, the "setDisabled(true)" function doesn't seem to be working. Is there some other way that I can accomplish this task?
You can disable text rendering by setting TextButton. TextTransparency to 1. This will leave you with a plain rectangle that can be used as a button.
Step 1: Add the ElevatedButton to your page. Step 2: Inside the ElevatedButton, assign the null value to the onPressed parameter. Step 3: Run the app. Similarly, you can disable the other buttons such as TextButton, OutlinedButton, FloatingActionButton, IconButton, etc.
You need to pass null to onPressed parameter of Buttons in Flutter to disable.
Found a solution: "newGameButton.setTouchable(Touchable.disabled);"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With