如何在继续时修改StepStepState [英] How to modify a Step StepState on continue

查看:85
本文介绍了如何在继续时修改StepStepState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照本教程 https://www.youtube.com/watch?v=izbkS2svuq4

并简要提到将StepState修改为StepState.editing,以便获得铅笔图标.

and there was a brief mention of modifying the StepState to StepState.editing so you get a pencil icon.

如何修改我正在执行的步骤的StepState,以便在我执行/粘贴该步骤时将其状态更改为编辑(或完成)

How can I modify the StepState of the step I am on so that it changes the state to editing (or complete) when I step on/past it

class _SimpleWidgetState extends State<SimpleWidget> {
  int _stepCounter = 0;

  List<Step> steps = [
    Step(
      title: Text("Step One"),
      content: Text("This is the first step"),
      isActive: true
    ),
    Step(
      title: Text("Step Two"),
      content: Text("This is the second step"),
      isActive: true,
    ),
    Step(
      title: Text("Step Three"),
      content: Text("This is the third step"),
      isActive: true,
    ),
    Step(
      title: Text("Step Four"),
      content: Text("This is the fourth step"),
      isActive: true,
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Stepper(
        steps: steps,
        currentStep: this._stepCounter,
        type: StepperType.vertical,
        onStepTapped: (step) {
          setState(() {
            _stepCounter = step;
            steps[step].state = StepState.editing; // this does not work but is what Im trying to accomplish
          });
        },
        onStepCancel: () {
          setState(() {
            _stepCounter > 0 ? _stepCounter -= 1 : _stepCounter = 0;
          });
        },
        onStepContinue: () {
          setState(() {
            _stepCounter < steps.length - 1 ? _stepCounter += 1 : _stepCounter = 0;
          });
        },
      ),
    );
  }
}

推荐答案

将步骤列表声明移至 build方法并声明每个步骤的 state 字段实例第一步: _stepCounter == 0?StepState.editing:StepState.indexed 并删除此行 steps [step] .state = StepState.editing; ,因为 .state 是最终的,因此不能被改变.

Move the Step list declaration into the build method and declare the state field of each step as for instance first step: _stepCounter == 0 ? StepState.editing : StepState.indexed and remove this line steps[step].state = StepState.editing; because .state is final and therefore can't be changed.

这篇关于如何在继续时修改StepStepState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆