如何在 FLUTTER 的步进器中显示列表

How to display a list in a step of stepper in FLUTTER

我正在尝试一个接一个地上传文档并使用 ListView 在列表中显示它们,但是当我单击第 4 步时,没有任何反应。第4步未开启

这是图片

这是代码

  List<Step> steps = [
Step(
  isActive: false,
  state: StepState.indexed,
  title: const Text('Attach your DOCUMENTS'),
  content: Column(
    children: <Widget>[
          ListView.builder(
            itemCount: documents.length,
            itemBuilder: (context, index) {
              final item = documents[index];

              return ListTile(
                title: Text("$item"),
              );
            },
          ),
      Container(
        child: MouseRegion(
          cursor: SystemMouseCursors.click,
          child: GestureDetector(
            child: Icon(
              Icons.upload_file,
              color: Colors.grey,
            ),
            // onTap: () => {}
          ),
        ),
      )
    ],
  ),
),

];

Scaffold(
  body: SafeArea(
    child: Container(
      child: Stepper(
          steps: steps,
          currentStep: currentStep,
          onStepContinue: next,
          onStepTapped: (step) => goTo(step),
          onStepCancel: cancel,
          type: StepperType.vertical,
          controlsBuilder: (BuildContext context, {VoidCallback onStepContinue, VoidCallback onStepCancel}) {
            return Column(
              children: <Widget>[
                SizedBox(height: size.width * 0.02),
                Row(
                  mainAxisAlignment: MainAxisAlignment
                      .start,
                  crossAxisAlignment: CrossAxisAlignment
                      .start,
                  children: <Widget>[
                    FlatButton(
                      color: Color(0XFFEFEFEF),
                      textColor: primaryColor,
                      disabledColor: Colors.grey,
                      disabledTextColor: Colors
                          .black,
                      padding: EdgeInsets.symmetric(
                          vertical: 15.0,
                          horizontal: 10.0),
                      onPressed: cancel,
                      child: Text(
                        "Back",
                        style: TextStyle(
                          fontSize: 15.0,
                        ),
                      ),
                    ),
                    SizedBox(width: size.width * 0.02),
                    FlatButton(
                      color: primaryColor,
                      textColor: Colors.white,
                      disabledColor: Colors.grey,
                      disabledTextColor: Colors
                          .black,
                      padding: EdgeInsets.symmetric(
                          vertical: 15.0,
                          horizontal: 10.0),
                      onPressed: next,
                      child: Text(
                        "Next",
                        style: TextStyle(
                          fontSize: 15.0,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            );
          }
      )

我正在 API 响应中获取文档,如下所示:

documents = ["doc1", "doc2"];

我不知道我们是否可以在步进器中显示列表。 还有其他方法吗?

提前致谢!!

尝试为 ListView 小部件放置 shrinkWrap: true 或用 Expanded 小部件包装它。 这是 dartpad.

中的一个实例
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _currentStep = 0;
  List<String> documents = ['file1.rst', 'file_2.txt', 'file_3.pdf'];
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'App',
      home: new Scaffold(
        appBar: new AppBar(title: new Text('App')),
        body: new Stepper(
          type: StepperType.vertical,
          currentStep: _currentStep,
          onStepTapped: (int step) => setState(() => _currentStep = step),
          onStepContinue:
              _currentStep < 2 ? () => setState(() => _currentStep += 1) : null,
          onStepCancel:
              _currentStep > 0 ? () => setState(() => _currentStep -= 1) : null,
          steps: <Step>[
            new Step(
              title: new Text('Shipping'),
              content: new Text('This is the first step.'),
              isActive: _currentStep >= 0,
              state:
                  _currentStep >= 0 ? StepState.complete : StepState.disabled,
            ),
            new Step(
              title: new Text('Payment'),
              content: Column(
                children: <Widget>[
                  ListView.builder(
                    shrinkWrap: true,
                    itemCount: documents.length,
                    itemBuilder: (context, index) {
                      final item = documents[index];

                      return ListTile(
                        title: Text("$item"),
                      );
                    },
                  ),
                  Container(
                    child: MouseRegion(
                      child: GestureDetector(
                        child: Icon(
                          Icons.upload_file,
                          color: Colors.grey,
                        ),
                        // onTap: () => {}
                      ),
                    ),
                  )
                ],
              ),
              isActive: _currentStep >= 0,
              state:
                  _currentStep >= 1 ? StepState.complete : StepState.disabled,
            ),
            new Step(
              title: new Text('Order'),
              content: new Text('This is the third step.'),
              isActive: _currentStep >= 0,
              state:
                  _currentStep >= 2 ? StepState.complete : StepState.disabled,
            ),
          ],
        ),
      ),
    );
  }
}

如果您遇到其他问题,请考虑使用您遇到的错误更新 post。