我需要一个Stepper来显示一些东西的当前状态(在步骤中)。因此,我想一次显示所有状态的内容。我删除了默认的Continue和Cancel按钮,但它只显示第一步的内容。
这是我的代码:
body: Center(
child: new Stepper(
steps: my_steps,
controlsBuilder: (BuildContext context,
{VoidCallback onStepContinue, VoidCallback onStepCancel}) {
return Row(
children: <Widget>[
Container(
child: null,
),
Container(
child: null,
),
],
);
},
),
),下面是我的步骤:
List<Step> my_steps = [
new Step(
title: new Text("Step 1"),
content: new Text("Hello 1!")),
new Step(
title: new Text("Step 2"),
content: new Text("Hello 2!")
),
new Step(
title: new Text("Step 3"),
content: new Text("Hello World!"),
)
];在这里,它只显示第一步的"Hello 1“。对于其余部分,内容是空的。
有没有人?
发布于 2019-12-10 04:45:39
您只需在步骤中使用isActive标记,即可显示用户已完成的所有状态。我想这会帮助你显示当前的状态。
要设置标记的所有状态-
bool getIsActive(int currentIndex, int index){
if(currentIndex<=index){
return true;
}else{
return false;
}
}和你的代码
body: Center(
child: new Stepper(
steps: [
new Step(
title: new Text("Step 1"),
content: new Text("Hello 1!"),
isActive: getIsActive(0,_index),
),
new Step(
title: new Text("Step 2"),
content: new Text("Hello 2!"),
isActive: getIsActive(1,_index),
),
new Step(
title: new Text("Step 3"),
content: new Text("Hello World!"),,
isActive: getIsActive(2,_index),
)
],
controlsBuilder: (BuildContext context,
{VoidCallback onStepContinue, VoidCallback onStepCancel}) => Container(),
),
),发布于 2020-02-04 19:46:07
我做到了:
flutter/lib/src/material/stepper.dart克隆到项目中的另一个目录。例如,您复制它并将新modified_stepper.dart中的两个类名重命名为您的/lib/widget/modified_stepper.dart.Stepper和Step。例如,将它们重命名为ModifiedStepper和ModifiedStep.(提示:如果你使用的是Visual Studio Code,你可以使用多个光标来更快地执行重命名,方法是将光标移到类名上,然后按Ctrl + F2 (Windows)或Cmd + F2 (Mac))
_isCurrent,它将如下所示:bool _isCurrent(int index) {
return widget.currentStep == index;
}此方法用于检测当前显示的是哪个步骤:如果currentStep等于该步骤的index,则显示该步骤。所以,简单地做一个小把戏:返回true将始终按照您期望的方式工作:
bool _isCurrent(int index) {
return true;
// return widget.currentStep == index;
}现在你可以导入你的ModifiedStepper来使用了。
发布于 2019-02-26 08:25:23
根据我对你的问题的理解,你实际上有两个问题。
示例代码中有一个bug。
由于修复问题#2不会以任何方式解决问题#1,因此我将提出以下建议作为您的解决方案:
Flutter的Stepper Widget相互工作的隐式方式排除了同时显示处于活动状态的所有步骤。从根本上说,Stepper并不是为做你想做的事情而设计的。在您的例子中,一种更好的方法可能是使用类似ListBuilder的代码:
import 'dart:io' as Io;
import 'package:flutter/material.dart';
class zListTileExample extends StatefulWidget {
zListTileExample({Key key}) : super(key: key);
@override
zListTileExampleState createState() => zListTileExampleState();
}
class zListTileExampleState extends State <zListTileExample> {
List<SampleStepTile> my_steps = [
new SampleStepTile(
title: new Text("Step 1"),
content: new Text("Hello 1!")),
new SampleStepTile(
title: new Text("Step 2"),
content: new Text("Hello 2!")
),
new SampleStepTile(
title: new Text("Step 3"),
content: new Text("Hello World!"),
)
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("My App Title"),
),
body:
ListView.builder(
itemCount: my_steps.length,
itemBuilder: (context, index) {
return
Column ( children: <Widget> [
ListTile(
title: my_steps[index].title ,
subtitle: my_steps[index].content
)
, Row ( children : <Widget> [
RaisedButton ( child: new Text ("Use")
, onPressed: () { print ("Step $index is ok");}),
RaisedButton ( child: new Text ("Cancel")
, onPressed: () { print ("Step $index is canceled");})
]
)
]
);
},
)
);
}
}
class SampleStepTile {
SampleStepTile({Key key, this.title, this.content });
Text title;
Text content;
}https://stackoverflow.com/questions/54875152
复制相似问题