在Flutter中创建进度条指示器形状

时间:2020-04-29 16:47:15

标签: flutter dart

我们对带有进度指示器的交付系统存在问题。有谁能建议一个用于扑动的进度指示器库。进度具有形状设计。下面的示例图片。

Progress indicator image sample

2 个答案:

答案 0 :(得分:1)

您可以在下面复制粘贴运行完整代码
您可以使用软件包https://pub.dev/packages/clippy_flutterhttps://pub.dev/packages/step_progress_indicator
当步骤index == 0时,返回Point,否则返回Chevron

代码段

StepProgressIndicator(
      totalSteps: 3,
      currentStep: 2,
      size: 20,
      selectedColor: Colors.orangeAccent,
      unselectedColor: Colors.grey,
      customStep: (index, color, _) => index == 0
          ? Point(
              triangleHeight: 20.0,
              edge: Edge.RIGHT,
              child: Container(
                color: color,
                child: Center(child: Text('')),
              ))
          : Chevron(
              triangleHeight: 20.0,
              edge: Edge.RIGHT,
              child: Container(
                color: color,
                child: Center(child: Text('')),
              )),
    ),

工作演示

enter image description here 完整代码

import 'package:flutter/material.dart';
import 'package:clippy_flutter/clippy_flutter.dart';
import 'package:step_progress_indicator/step_progress_indicator.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            StepProgressIndicator(
              totalSteps: 3,
              currentStep: 2,
              size: 20,
              selectedColor: Colors.orangeAccent,
              unselectedColor: Colors.grey,
              customStep: (index, color, _) => index == 0
                  ? Point(
                      triangleHeight: 20.0,
                      edge: Edge.RIGHT,
                      child: Container(
                        color: color,
                        child: Center(child: Text('')),
                      ))
                  : Chevron(
                      triangleHeight: 20.0,
                      edge: Edge.RIGHT,
                      child: Container(
                        color: color,
                        child: Center(child: Text('')),
                      )),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

答案 1 :(得分:1)

您可以使用Row,Containers和CustomClipper类实现此目的。我已经为此创建了一个库。您可以从以下位置使用该库:progress_stepper

以下代码创建一个步进器:

ProgressStepper(                              
   width: 300,
   height: 15,
   stepCount: 5,
   builder: (index) {
      double widthOfStep = 300 / 5;
      if (index == 1) {
         return ProgressStepWithArrow(
            width: widthOfStep,
            defaultColor: Color(0xFFCECECF),
            progressColor: Color(0xFFFBB040),
            wasCompleted: true,
         );
      }
      return ProgressStepWithChevron(
         width: widthOfStep,
         defaultColor: Color(0xFFCECECF),
         progressColor: Color(0xFFFBB040),
         wasCompleted: false,
      );
   },
)

它将创建一个步进器,如下图所示:

Progress Stepper