简体   繁体   中英

Create a progress bar indicator shapes in flutter

We have a problem about our delivery system with progress indicator. Does anyone can suggest a library of progress indicator for flutter. The progress has a shape design. The sample image below.

Progress indicator image sample

You can copy paste run full code below
You can use package https://pub.dev/packages/clippy_flutter and https://pub.dev/packages/step_progress_indicator
When step index == 0 return Point else return Chevron

code snippet

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('')),
              )),
    ),

working demo

在此处输入图像描述 full code

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

You can achieve this using a Row, Containers and CustomClipper class. I've created a library for this purpose. You can use the library from here: progress_stepper .

The following code creates a 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,
      );
   },
)

It will create a Stepper like the following image:

进度步进器

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM