【问题标题】:Is there a way to create flutter stepper from a for loop and set active step?有没有办法从 for 循环创建颤振步进器并设置活动步骤?
【发布时间】:2020-10-02 03:37:48
【问题描述】:

我正在将一些数据从 API 提取到步进器小部件中。数据返回一个类别列表,这些类别有一个问题列表。我想将类别名称设置为步骤及其对步骤内容的问题。 这就是我获取类别和构建步骤的方式

  void _getCategories() async {
var res = await Network().getData("/questions");
//check if success
if (res.statusCode == 200) {
  var body = json.decode(res.body);
  var data = body['flow']['categories'];
  HashMap<String, Object> temp = new HashMap<String, Object>();
  for (var category in data) {
    temp.putIfAbsent(category['description'], () => category['questions']);
  }
  setState(() {
    categories = temp;
  });
  _buildSteps();
}
}

然后我建立一个步骤列表:

  void _buildSteps() {
categories.forEach((key, value) {
  steps.add(Step(
      title: Text(key), content: Text(key), isActive: currentStep >= 0));
});

}

使用

currentStep >= 0

将所有步骤设置为活动,但我只想将第一步设置为当前步骤,当单击继续时,它将设置下一步为活动。

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:
    List<Step> getSteps() {
      List<Step> mySteps = [];
       for(int i = 0; i< 5; i++) {
         final _step = Step(title: Text('$i'), content: Container(), isActive: true);
         mySteps.add(_step);
       }
       return mySteps;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      相关资源
      最近更新 更多