[解决方案1]:
Stepper Widget 中没有设置/更改按钮的属性
您可以使用 enhance_stepper 包进行修改。
Widget buildStepperCustom(BuildContext context) {
return EnhanceStepper(
stepIconSize: 30,
type: _type,
horizontalTitlePosition: HorizontalTitlePosition.bottom,
horizontalLinePosition: HorizontalLinePosition.top,
currentStep: _index,
physics: ClampingScrollPhysics(),
steps: tuples.map((e) => EnhanceStep(
icon: Icon(e.item1, color: Colors.blue, size: 30,),
state: StepState.values[tuples.indexOf(e)],
isActive: _index == tuples.indexOf(e),
title: Text("step ${tuples.indexOf(e)}"),
subtitle: Text("${e.item2.toString().split(".").last}",),
content: Text("Content for Step ${tuples.indexOf(e)}"),
)).toList(),
onStepCancel: () {
go(-1);
},
onStepContinue: () {
go(1);
},
onStepTapped: (index) {
ddlog(index);
setState(() {
_index = index;
});
},
controlsBuilder: (BuildContext context, { VoidCallback? onStepContinue, VoidCallback? onStepCancel }){
return Row(
children: [
SizedBox(height: 30,),
ElevatedButton(
onPressed: onStepContinue,
child: Text("Next"),
),
SizedBox(width: 8,),
TextButton(
onPressed: onStepCancel,
child: Text("Back"),
),
],
);
}
);
【讨论】:
[解决方案2]:
我使用的是布尔值,因为 lastField 设置为 false。
在步骤继续和步骤取消中,我检查当前步骤是否是最后一步并适当地更改 lastField。
然后您可以根据 lastField 更改控件生成器。
所以我的 on step continue 看起来像这样:
onStepContinue: (){
if(forms[_currentStep].currentState!.validate()){
_currentStep < 3 ?
setState((){
_currentStep += 1;
if(_currentStep == 3){
lastField = true;
}else{
lastField = false;
}
}): null;
}
},
我的控件生成器如下所示:
controlsBuilder: (context, details){
return Padding(
padding: const EdgeInsets.all(8.0),
child: lastField ? Row(
children: [
ElevatedButton(onPressed: (){}, child: const Text("Submit"), style: ElevatedButton.styleFrom(primary: buttonPurple, shape: const StadiumBorder()),),
TextButton(onPressed: details.onStepCancel, child: const Text("Cancel", style: TextStyle(color: Colors.white70),))
],
) : Row(
children: [
ElevatedButton(onPressed: details.onStepContinue, child: const Text("Next"), style: ElevatedButton.styleFrom(primary: buttonPurple, shape: const StadiumBorder()),),
TextButton(onPressed: details.onStepCancel, child: const Text("Cancel", style: TextStyle(color: Colors.white70),))
],
)
);
},
【讨论】:
© 版权声明
本站下载的源码均来自公开网络收集转发二次开发而来,
若侵犯了您的合法权益,请来信通知我们1413333033@qq.com,
我们会及时删除,给您带来的不便,我们深表歉意。
下载用户仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,访问及下载者下载默认同意本站声明的免责申明,请合理使用切勿商用。
THE END
暂无评论内容