Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable in flutter stepper the first cancel button

Tags:

flutter

I currently have a stepper that also works perfectly, but I have the question how to disable the back button at the first step, but in the others it should be displayed.

I modified the stepper with the controlsBuilder but i didnt found a solution where i can disable the back button.

Thanks in advance

Here is a small code snippet from my stepper (not fully):

 controlsBuilder: (BuildContext context,
                    {VoidCallback onStepContinue, VoidCallback onStepCancel}) {
                  return Row(
                    children: <Widget>[
                      FlatButton(
                        onPressed: onStepContinue,
                        child: const Text('Weiter',
                            style: TextStyle(color: Colors.white)),
                        color: Colors.blue,
                      ),
                      new Padding(
                        padding: new EdgeInsets.all(10),
                      ),
                      FlatButton(
                        onPressed: onStepCancel,
                        child: const Text(
                          'Zurück',
                          style: TextStyle(color: Colors.white),
                        ),
                        color: Colors.blue,
                      ),
                    ],
                  );
                },



List<Step> steps = [
      Step(
        title: const Text('TEST'),
        isActive: true,
        state: StepState.complete,
        content: Column(children: <Widget>[
          RadioListTile(
            value: 1,
            groupValue: selectedRadioTile,
            title: Text("XX"),
            onChanged: (val) {
              setSelectedRadioTile(val);
            },
            activeColor: Colors.blue,
            selected: true,
          ),
          RadioListTile(
            value: 2,
            groupValue: selectedRadioTile,
            title: Text("XX"),
            onChanged: (val) {
              setSelectedRadioTile(val);
            },
            activeColor: Colors.blue,
            selected: false,
          ),
        ]),
      ),```
like image 645
CodOG Avatar asked Jul 12 '19 08:07

CodOG


People also ask

How do you remove continue and cancel button from stepper in flutter?

Solution for flutter version > 2.8.1controlsBuilder: (context, {onStepContinue, onStepCancel}) {...} Or this: controlsBuilder: (context, onStepContinue) {...} controlsBuilder: (context, onStepCancel) {...}

How do you hide the button of the stepper in flutter?

bool hide = false; Then use controlsBuilder in the stapper.

How do you customize stepper in flutter?

Creating Stepper In Flutter To create a stepper we have to call the constructor of the stepper class provided by flutter and provide required properties. There is one required property for stepper widget which is steps. The value for this property should be a list whose children are step widgets.


1 Answers

If I understand correctly you want to disable the "Cancel" button conditionally.

You will somehow need to know whether it is the first screen or not. Let's say you have that in a variable called isFirstScreen that you pass to your controlsBuilder method. Then you can disable the button with a ternary operator on the onPressed handler like this:

FlatButton(
  onPressed: isFirstScreen ? null : onStepCancel, // <-- important part
  child: const Text(
    'Zurück',
    style: TextStyle(color: Colors.white),
  ),
  color: Colors.blue,
),

From the Flutter FlatButton docs:

If the onPressed callback is null, then the button will be disabled, will not react to touch, and will be colored as specified by the disabledColor property instead of the color property.

like image 141
Tim Klingeleers Avatar answered Oct 03 '22 02:10

Tim Klingeleers