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,
),
]),
),```
Solution for flutter version > 2.8.1controlsBuilder: (context, {onStepContinue, onStepCancel}) {...} Or this: controlsBuilder: (context, onStepContinue) {...} controlsBuilder: (context, onStepCancel) {...}
bool hide = false; Then use controlsBuilder in the stapper.
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.
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.
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