【问题标题】:how to show Progress Bar for delivery updation in flutter如何在颤动中显示进度条以进行交付更新
【发布时间】:2020-01-22 09:19:37
【问题描述】:

我想在我的应用程序中添加一个进度条,但我不知道该怎么做。我只是一个初学者,想学习如何添加进度条 in 交付应用程序

【问题讨论】:

标签: flutter


【解决方案1】:

六个月后。我将把它留在这里以供将来参考。不要使用步进器小部件来实现这一点。它相当僵硬。请改用时间线小部件。时间线图块对我来说效果很好。 https://pub.dev/packages/timeline_tile

【讨论】:

    【解决方案2】:

    添加步骤

    // 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,
        ),
      ];
    

    添加步进器

    @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;
                  }
                });
              },
            ),
          ),
        );
      }
    

    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;
                  }
                });
              },
            ),
          ),
        );
      }
    }
    

    【讨论】:

    • @kunaldawar 如果我的回答对您有帮助,请随时接受它
    • 是的,它很有帮助,但我需要更多的装饰,我有一个问题,如何删除这两个按钮继续并在那个 ui 中取消??
    猜你喜欢
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    相关资源
    最近更新 更多