我正在使用Stepper Widget 来制作更改 PinCode 表单。一切正常,但我不知道如何禁用之前的步进点击。
例子 :
如果我在第 2 步中单击步进器,我不想返回到第 1 步。
我该如何解决这个问题?
Form(
key: _formKey,
child: Stepper(
steps: steps(),
currentStep: currStep,
onStepContinue: () {
setState(() {
if (formKeys[currStep].currentState.validate()) {
if (currStep < steps().length - 1) {
currStep += 1;
} else if (steps().length == 2) {
print('Done');
} else {
currStep = 0;
}
}
});
},
onStepTapped: (step) {
setState(() {
currStep = step;
print(step);
});
},
),
),
List<Step> steps() {
return [
Step(
title: const Text('Enter Previous PinCode'),
isActive: currStep == 0 ? true : false,
state: StepState.indexed,
content: Form(
key: formKeys[0],
child: TextFormField(
autofocus: true,
keyboardType: TextInputType.number,
validator: (value) {
if (value.isEmpty || value != userModelHive.pinCodeNumber) {
return 'PinCode Invalid';
}
return null;
},
),
),
),
Step(
title: const Text('Enter New PinCode'),
isActive: true,
state: StepState.indexed,
content: Form(
key: formKeys[1],
child: TextFormField(
autofocus: true,
keyboardType: TextInputType.number,
validator: (value) {
if (value.isEmpty) {
return 'Provided PinCode';
} else if (value.length < 4 || value.length > 6) {
return "More than 4 Less than 6";
}
return null;
},
),
),
),
];
}
Run Code Online (Sandbox Code Playgroud)
小智 5
只需检查天气中的step变量onStepTapped是否为之前的……如果是上一步,则不要调用setState
Stepper(
steps:steps(),
currentStep:currentStep,
onStepTapped:(step){
if(step>currentStep){
setState((){
currentStep=step;
});
}
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1069 次 |
| 最近记录: |