Flutter 如何在Flatter中显示交付更新的进度条

Flutter 如何在Flatter中显示交付更新的进度条,flutter,Flutter,我想在我的应用程序中添加一个进度条,但我不知道怎么做。我刚刚开始学习颤振,想学习如何在交付应用程序中添加进度条添加步骤 // Step Counter int current_step = 0; List<Step> steps = [ Step( title: Text('Step 1'), content: Text('Hello!'), isActive: true, ), Step( title: T

我想在我的应用程序中添加一个进度条,但我不知道怎么做。我刚刚开始学习颤振,想学习如何在交付应用程序中添加进度条

添加步骤

// Step Counter
int current_step = 0;

 List<Step> steps = [
    Step(
      title: Text('Step 1'),
      content: Text('Hello!'),
      isActive: true,
    ),
    Step(
      title: Text('Step 2'),
      content: Text('World!'),
      isActive: true,
    ),
    Step(
      title: Text('Step 3'),
      content: Text('Hello World!'),
      state: StepState.complete,
      isActive: true,
    ),
  ];
//步进计数器
int电流_阶跃=0;
列出步骤=[
台阶(
标题:文本(“步骤1”),
内容:Text('Hello!'),
是的,
),
台阶(
标题:文本(“步骤2”),
内容:文本('World!'),
是的,
),
台阶(
标题:文本(“步骤3”),
内容:Text('Hello World!'),
状态:StepState.complete,
是的,
),
];
添加步进器

@override
  Widget build(BuildContext context) {
    return Scaffold(
      // Appbar
      appBar: AppBar(
        // Title
        title: Text("Simple Stepper Demo"),
      ),
      // Body
      body: Container(
        child: Stepper(
          currentStep: this.current_step,
          steps: steps,
          type: StepperType.vertical,
          onStepTapped: (step) {
            setState(() {
              current_step = step;
            });
          },
          onStepContinue: () {
            setState(() {
              if (current_step < steps.length - 1) {
                current_step = current_step + 1;
              } else {
                current_step = 0;
              }
            });
          },
          onStepCancel: () {
            setState(() {
              if (current_step > 0) {
                current_step = current_step - 1;
              } else {
                current_step = 0;
              }
            });
          },
        ),
      ),
    );
  }
@覆盖
小部件构建(构建上下文){
返回脚手架(
//Appbar
appBar:appBar(
//头衔
标题:文本(“简单步进演示”),
),
//身体
主体:容器(
孩子:步进机(
currentStep:此.current\u步骤,
步骤:步骤,
类型:StepperType.vertical,
步骤:(步骤){
设置状态(){
当前步进=步进;
});
},
onStepContinue:(){
设置状态(){
if(当前步数<步数长度-1){
当前步进=当前步进+1;
}否则{
当前步进=0;
}
});
},
onStepCancel:(){
设置状态(){
如果(当前步骤>0){
当前步进=当前步进-1;
}否则{
当前步进=0;
}
});
},
),
),
);
}
onStepTapped将设置当前步进器计数。 onStepContinue将递增步进计数器,并对将其设置为下一个计数器的变量调用setState。 onStepCancel将减小步进计数器并返回到上一步

完整代码

import 'package:flutter/material.dart';

class StepperDemo extends StatefulWidget {
  StepperDemo() : super();

  final String title = "Stepper Demo";

  @override
  StepperDemoState createState() => StepperDemoState();
}

class StepperDemoState extends State<StepperDemo> {
  //
  int current_step = 0;
  List<Step> steps = [
    Step(
      title: Text('Step 1'),
      content: Text('Hello!'),
      isActive: true,
    ),
    Step(
      title: Text('Step 2'),
      content: Text('World!'),
      isActive: true,
    ),
    Step(
      title: Text('Step 3'),
      content: Text('Hello World!'),
      state: StepState.complete,
      isActive: true,
    ),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // Appbar
      appBar: AppBar(
        // Title
        title: Text("Simple Stepper Demo"),
      ),
      // Body
      body: Container(
        child: Stepper(
          currentStep: this.current_step,
          steps: steps,
          type: StepperType.vertical,
          onStepTapped: (step) {
            setState(() {
              current_step = step;
            });
          },
          onStepContinue: () {
            setState(() {
              if (current_step < steps.length - 1) {
                current_step = current_step + 1;
              } else {
                current_step = 0;
              }
            });
          },
          onStepCancel: () {
            setState(() {
              if (current_step > 0) {
                current_step = current_step - 1;
              } else {
                current_step = 0;
              }
            });
          },
        ),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
类StepherDemo扩展StatefulWidget{
StepperDemo():super();
最终字符串标题=“步进器演示”;
@凌驾
StepherDemostate createState()=>StepherDemostate();
}
类StepherDemoState扩展了状态{
//
int电流_阶跃=0;
列出步骤=[
台阶(
标题:文本(“步骤1”),
内容:Text('Hello!'),
是的,
),
台阶(
标题:文本(“步骤2”),
内容:文本('World!'),
是的,
),
台阶(
标题:文本(“步骤3”),
内容:Text('Hello World!'),
状态:StepState.complete,
是的,
),
];
@凌驾
小部件构建(构建上下文){
返回脚手架(
//Appbar
appBar:appBar(
//头衔
标题:文本(“简单步进演示”),
),
//身体
主体:容器(
孩子:步进机(
currentStep:此.current\u步骤,
步骤:步骤,
类型:StepperType.vertical,
步骤:(步骤){
设置状态(){
当前步进=步进;
});
},
onStepContinue:(){
设置状态(){
if(当前步数<步数长度-1){
当前步进=当前步进+1;
}否则{
当前步进=0;
}
});
},
onStepCancel:(){
设置状态(){
如果(当前步骤>0){
当前步进=当前步进-1;
}否则{
当前步进=0;
}
});
},
),
),
);
}
}

六个月后。我把这个放在这里,以备将来参考。不要使用stepper小部件来实现这一点。它很硬。改用时间轴小部件。时间线瓷砖对我很有效


使用Stepper Widget@kunaldawar如果我的答案对您有帮助,那么请随意接受。是的,它很有帮助,但我需要更多装饰,我有一个问题,如何删除这两个按钮继续并在该ui中选择??