Updated 28 April 2023
In this blog, we are going to learn about how to create STEPPER in Flutter. So let’s get started.
In Material Design, the STEPPER is a widget that displays progress through a sequence of steps.
It is mostly useful in the case of forms where one step requires the completion of another one.
Check out more about our Flutter app development.
1.) Create a Scaffold.
2.) Display a Stepper and initialized Stepper(). Inside Stepper, we created a method called mySteps()
3.) Provide an optional action.
Inside Scaffold widgets, it Implements the basic material design visual layout structure.
This class provides APIs for showing drawers and bottom sheets. We can add the background color inside the scaffold widget.
It also supports special Material Design components, such as Drawers, AppBars, and SnackBars.
We have provided the example below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
void main() => runApp(DemoStepper()); class DemoStepper extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Test Demo Stepper', home: Scaffold( appBar: AppBar( title: const Text('Test Demo Stepper'), ), body: const DemoStepperHomePage(), ), ); //MaterialApp } } |
First, create a stepper, then initialized stepper.
This method is created because we have created the list of steps that are required in the form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
class DemoStepperHomePage extends StatefulWidget { @override _DemoStepperState createState() => _DemoStepperState(); } class _DemoStepperState extends State<DemoStepper> { int firstStep = 0; List<Step> mySteps = [ Step(title: Text("First step"), content: Text("Personal details"), isActive: true), Step( title: Text("Second step"), content: Text("Residence address"), state: StepState.editing, isActive: true), Step( title: Text("Third step"), content: Text("Educational details."), state: StepState.editing, isActive: true), Step( title: Text("Fourth step"), content: Text("Payment"), state: StepState.editing, isActive: true), Step(title: Text("Fifth step"), content: Text("Receipt"), isActive: true), ]; } |
Now, we need to provide an action to the user when the Stepper is displayed.
Here’s an example of providing full code of Stepper widget:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
class _DemoStepperState extends State<DemoStepper> { int firstStep = 0; List<Step> mySteps = [ Step(title: Text("First step"), content: Text("Personal details"), isActive: true), Step( title: Text("Second step"), content: Text("Residence address"), state: StepState.editing, isActive: true), Step( title: Text("Third step"), content: Text("Educational details."), state: StepState.editing, isActive: true), Step( title: Text("Fourth step"), content: Text("Payment"), state: StepState.editing, isActive: true), Step(title: Text("Fifth step"), content: Text("Receipt"), isActive: true), ]; @override Widget build(BuildContext context) { return Container( child: Stepper( currentStep: this.currentStep, steps: mySteps, type: StepperType.vertical, onStepTapped: (step) { setState(() { currentStep = step; }); }, onStepCancel: () { setState(() { if (currentStep > 0) { currentStep = currentStep - 1; } else { currentStep = 0; } }); }, onStepContinue: () { setState(() { if (currentStep < mySteps.length - 1) { currentStep = currentStep + 1; } else { currentStep = 0; } }); }, )); } } |
We can now run the app on how to create STEPPER in flutter.
Hope this blog helps you to create an stepper in a flutter.
So, I hope it will help you out in understanding and getting a brief idea about it.
For more understanding please can go through this Link:
That’s all, You can enjoy your Stepper implementation in a flutter.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.