Steps Indicator In Flutter :
in this flutter tutorial we will learn how to design steps indicator in flutter. steps indicator is normally used for indicate the steps. for example when we open any app first time then the app indicates the step for use it, it calls steps indicator so today we design the steps indicator in flutter
to design steps indicator in flutter first we need to add dependency after add dependency import it.
Add steps_indicator: ^0.3.1
in your pubspec.yaml
import 'package:steps_indicator/steps_indicator.dart';
How to Use :
first create the StepsIndicator widget and then pass the required parameters
For Example :
StepsIndicator( selectedStep: 1, nbSteps: 4 )
Note : the selectedStep is not allowed if it is lower than 0 and nbSteps should not be higher than the total number of steps
the list of parameters you can use to design steps indicator in flutter that is listed below
StepsIndicator( selectedStep: 2, nbSteps: 5, selectedStepColorOut: Colors.green, selectedStepColorIn: Colors.orange, doneStepColor: Colors.green, unselectedStepColor: Colors.blue, doneLineColor: Colors.green, undoneLineColor: Colors.blue, isHorizontal: true/false, lineLength: 30, lineThickness: 2, doneStepSize: 5, unselectedStepSize: 5, selectedStepSize: 15, selectedStepBorderSize: 2, doneStepWidget: Container(), // Custom Widget unselectedStepWidget: Container(), // Custom Widget selectedStepWidget: Container(), // Custom Widget )
here is a small example of steps indicator in flutter. to know more about steps indicator study it
Screenshot :

steps_indicator.dart
library steps_indicator; import 'package:flutter/material.dart'; class StepsIndicator extends StatelessWidget { final int selectedStep; final int nbSteps; final Color selectedStepColorOut; final Color selectedStepColorIn; final Color doneStepColor; final Color unselectedStepColor; final Color doneLineColor; final Color undoneLineColor; final bool isHorizontal; final double lineLength; final double lineThickness; final double doneStepSize; final double unselectedStepSize; final double selectedStepSize; final double selectedStepBorderSize; final Widget doneStepWidget; final Widget unselectedStepWidget; final Widget selectedStepWidget; const StepsIndicator( {this.selectedStep = 0, this.nbSteps = 4, this.selectedStepColorOut = Colors.blue, this.selectedStepColorIn = Colors.white, this.doneStepColor = Colors.blue, this.unselectedStepColor = Colors.blue, this.doneLineColor = Colors.blue, this.undoneLineColor = Colors.blue, this.isHorizontal = true, this.lineLength = 40, this.lineThickness = 1, this.doneStepSize = 10, this.unselectedStepSize = 10, this.selectedStepSize = 14, this.selectedStepBorderSize = 1, this.doneStepWidget, this.unselectedStepWidget, this.selectedStepWidget}); @override Widget build(BuildContext context) { if (isHorizontal) { // Display in Row return Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ for (var i = 0; i < nbSteps; i++) stepBuilder(i), ], ); } else { // Display in Column return Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ for (var i = 0; i < nbSteps; i++) stepBuilder(i), ], ); } } Widget stepBuilder(int i) { if (isHorizontal) { // Display in Row return (selectedStep == i ? Row( children: <Widget>[ stepSelectedWidget(), selectedStep == nbSteps ? stepLineDoneWidget() : Container(), i != nbSteps - 1 ? stepLineUndoneWidget() : Container() ], ) : selectedStep > i ? Row( children: <Widget>[ stepDoneWidget(), i < nbSteps - 1 ? stepLineDoneWidget() : Container(), ], ) : Row( children: <Widget>[ stepUnselectedWidget(), i != nbSteps - 1 ? stepLineUndoneWidget() : Container() ], )); } else { // Display in Column return (selectedStep == i ? Column( children: <Widget>[ stepSelectedWidget(), selectedStep == nbSteps ? stepLineDoneWidget() : Container(), i != nbSteps - 1 ? stepLineUndoneWidget() : Container() ], ) : selectedStep > i ? Column( children: <Widget>[ stepDoneWidget(), i < nbSteps - 1 ? stepLineDoneWidget() : Container(), ], ) : Column( children: <Widget>[ stepUnselectedWidget(), i != nbSteps - 1 ? stepLineUndoneWidget() : Container() ], )); } } Widget stepSelectedWidget() { return Hero( tag: 'selectedStep', child: selectedStepWidget != null ? selectedStepWidget : ClipRRect( borderRadius: BorderRadius.circular(selectedStepSize), child: Container( decoration: BoxDecoration( color: selectedStepColorIn, borderRadius: BorderRadius.circular(selectedStepSize), border: Border.all( width: selectedStepBorderSize, color: selectedStepColorOut)), height: selectedStepSize, width: selectedStepSize, child: Container()), ), ); } Widget stepDoneWidget() { return doneStepWidget != null ? doneStepWidget : ClipRRect( borderRadius: BorderRadius.circular(doneStepSize), child: Container( color: doneStepColor, height: doneStepSize, width: doneStepSize, child: Container(), ), ); } Widget stepUnselectedWidget() { return unselectedStepWidget != null ? unselectedStepWidget : ClipRRect( borderRadius: BorderRadius.circular(unselectedStepSize), child: Container( color: unselectedStepColor, height: unselectedStepSize, width: unselectedStepSize, child: Container(), ), ); } Widget stepLineDoneWidget() { return Container( height: isHorizontal ? lineThickness : lineLength, width: isHorizontal ? lineLength : lineThickness, color: doneLineColor); } Widget stepLineUndoneWidget() { return Container( height: isHorizontal ? lineThickness : lineLength, width: isHorizontal ? lineLength : lineThickness, color: undoneLineColor); } }
main.dart
import 'package:flutter/material.dart'; import 'steps_indicator.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Steps Indicator Example', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Steps Indicator Example'), ); } } 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 selectedStep = 0; int nbSteps = 5; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ StepsIndicator( selectedStep: selectedStep, nbSteps: nbSteps, doneLineColor: Colors.green, doneStepColor: Colors.green, undoneLineColor: Colors.red, unselectedStepColor: Colors.red, ), Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ MaterialButton( color: Colors.red, onPressed: () { if(selectedStep > 0) { setState(() { selectedStep--; }); } }, child: Text('Prev'), ), MaterialButton( color: Colors.green, onPressed: () { if(selectedStep < nbSteps) { setState(() { selectedStep++; }); } }, child: Text('Next'), ) ], ) ], ) ), ); } }
The flutter tutorial is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application
For more information about Flutter. visit www.fluttertutorial.in