dart - Flutter:Stepper onStepContinue不触发
问题描述
你能告诉我我的代码有什么问题吗?
Widget _createProfileStepper() {
int currentStep = 0;
List<Step> createAccSteps = [
new Step(
title: Container(),
content: new Text('This is the first step.'),
isActive: currentStep >= 0,
state: currentStep >= 0 ? StepState.editing : StepState.disabled,
),
new Step(
title: Container(),
content: new Text('This is the second step.'),
isActive: currentStep >= 0,
state: currentStep >= 1 ? StepState.editing : StepState.disabled,
),
new Step(
title: Container(),
content: new Text('This is the third step.'),
isActive: currentStep >= 0,
state: currentStep >= 2 ? StepState.editing : StepState.disabled,
),
new Step(
title: Container(),
content: new Text('This is the second step.'),
isActive: currentStep >= 0,
state: currentStep >= 3 ? StepState.editing : StepState.disabled,
),
new Step(
title: Container(),
content: new Text('This is the third step.'),
isActive: currentStep >= 0,
state: currentStep >= 4 ? StepState.editing : StepState.disabled,
),
];
return Scaffold(
appBar: AppBar(
title: Text("Create Profile"),
),
body: Stepper(
type: StepperType.horizontal,
currentStep: currentStep,
onStepTapped: (step) {
setState(() {
currentStep = step;
});
},
onStepContinue: () {
setState(() {
if (currentStep < createAccSteps.length - 1) {
currentStep = currentStep + 1;
} else {}
});
},
onStepCancel: () {
setState(() {
if(currentStep > 0){
currentStep = currentStep - 1;
}
else {
currentStep = 0;
}
});
},
steps: createAccSteps,
),
);
}
我遵循了 Flutter 步进器的所有示例,但仍然没有运气。我可以点击继续按钮,但它没有移动到另一个步骤。我是不是忘记了什么?我创建了一个有状态的 Widget 类,然后一个按钮会带我调用这个 _createProfileStepper()。谢谢。
解决方案
因此您无法从内部列表中访问您的 currentStep 以进行启动。
“isActive”也应该是一个布尔值(并且只影响样式https://docs.flutter.io/flutter/material/Step/isActive.html)
此外,将空的 Container() 作为标题似乎有点奇怪,您可以将其删除或将步骤号放在那里
尝试将您的步骤更改为
Step(
title: Text("Step One"),
content: new Text("This is the first step."),
isActive: true
),
推荐阅读
- dictionary - 手动复现dict底层代码的一个问题:value不能是object
- python-3.x - 检查列表中的项目
- python - 如何将基于函数的视图集成到 Django 中的基于类的视图中?
- roku - Roku Scenegraph SGDEX - 替换 HDPosterURL 变量
- php - 当分隔符有效时,explode() 偏移量和分隔符警告
- java - 无法在 wsimport 生成的源中获取具有类路径方案的 URL 的资源
- spring-boot - Spring Boot JPA 更新失败
- python - 如何为列中的每个不同值转发重采样
- php - 我已经设置了 web 和 api 防护,但使用护照登录总是访问 web 防护
- javascript - 如果数据设置为假值(null、false、未定义等),为什么 v-bind:style 不会对更改做出反应