【魔兽世界】Widget中没有设置/更改按钮的属性

[解决方案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),))
            ],
          )
        );
      },

【讨论】:

© 版权声明
THE END
喜欢就支持一下吧
点赞36赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容