Stepper Widget In Flutter

Ionic Firebase App
hireflutterdev
Published in
7 min readApr 19, 2023
Stepper Widget In Flutter

Flutter, which is a well-known user interface toolkit of Google, is doing really great to create lovely, natively compiled Android and iOS mobile apps from a single codebase. To create any sized mobile app, we being a reliable mobile app development company initiate start with widgets — the structure block of flutter apps. Widgets represent what their view must look like, given their current configuration & state. It incorporates a number of widgets which includes a column widget, row widget, container widget, text widget, and more.

Every single component you see on the screen of the Flutter mobile app is a widget. The perspective of the screen totally relies on the choice & grouping of the widgets utilized to develop the mobile app. Furthermore, the structure of the code of a mobile app is a tree of widgets.

In this blog, we are going to explore the Stepper Widget In Flutter. So, have a quick look at the blog and get the details.

Stepper Widget:

Material stepper widget, this is a widget that showcases progress through a succession’s steps. Stepper’s widgets are mainly valuable in view of forms where just one step needs another or where several steps should be ended to present the complete form.

Code Implement:

Inside the lib folder, simply generate a dart file called stepper_demo.dart.

We’ll need to pin into onStepTapped, onStepContinue, onStepCancel, & currenStepallow a user so that they can cycle through it.

Now we’ll generate an integer of the current step. The index into steps of the present step whose content is displayed.

int _currentStep = 0;

Then, onStepTapped, which is the callback. This is called when a particular step is tapped, and here the index will be passed as an argument. Here, we’ll create a tapped() widget & the code as shown below.

tapped(int step){
setState(() => _currentStep = step);
}

Now, when the ‘continue’ button is tapped, the onStepContinue is the callback called. If there is no value or say null, the ‘continue’ button will be disabled itself. We’ll create a continued() widget & the code, as shown below.

continued(){
_currentStep < 2 ?
setState(() => _currentStep += 1): null;
}

The time we tap on the ‘continue’ button, the step will automatically move forward to the next step.

Now, when the ‘cancel’ button is tapped, onStepCancel is the callback called. If it operates null, the ‘cancel’ button will be automatically disabled. We’ll create a cancel() widget & the code, as shown below.

cancel(){
_currentStep > 0 ?
setState(() => _currentStep -= 1) : null;
}

The time we click on the cancel button, then the step will automatically backward to the previous step.

Now, we’ll define the steps.

We’ll create a Stepper with 3 steps. We’ll deeply define all 3 steps below are:

Account Step

In the 1st step, we’ll be called an Account as the title. In this particular step, we’ll create 2 TextFormField called Email Address & Password.

Step(
title: new Text('Account'),
content: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: 'Email Address'),
),
TextFormField(
decoration: InputDecoration(labelText: 'Password'),
),
],
),
isActive: _currentStep >= 0,
state: _currentStep >= 0 ?
StepState.complete : StepState.disabled,
),

The time we tap on the continue button, the step will automatically move forward to the next step. The number was updated to an active tick icon. In this particular step, the cancel button won’t work.

Address Step

In the 2nd step, we’ll be called an Address, the title. Here, we’ll create 2 TextFormField called Home Address & Postcode.

Step(
title: new Text('Address'),
content: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: 'Home Address'),
),
TextFormField(
decoration: InputDecoration(labelText: 'Postcode'),
),
],
),
isActive: _currentStep >= 0,
state: _currentStep >= 1 ?
StepState.complete : StepState.disabled,
),

In this step, when we click on the continue button, the step will automatically move forward to the next step, & the number was changed to the active tick icon. When we click on the cancel button, the step will be automatically moved back to the previous step, & the active tick icon was changed to a number again.

Mobile Number Step

This is the last step, we‘ll be called a Mobile Number as the title. In this step, we’ll create one TextFormField called Mobile Number.

Step(
title: new Text('Mobile Number'),
content: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: 'Mobile Number'),
),
],
),
isActive:_currentStep >= 0,
state: _currentStep >= 2 ?
StepState.complete : StepState.disabled,
),

In this step, when we click on the continue button, the step will automatically move forward to the next step, & the number was changed to the active tick icon. The time the user will click on the cancel button, the step will be moved back to the previous step, & the active tick icon was changed to a number again.

Horizontal Step

In stepper, the direction will also be changed, so we generate a floating action button, & on this button, we call an icon & switchStepsType() widget.

floatingActionButton: FloatingActionButton(
child: Icon(Icons.list),
onPressed: switchStepsType,
),

Here we can define the switchStepsType() widget, deeply.

switchStepsType() {
setState(() => stepperType == StepperType.vertical
? stepperType = StepperType.horizontal
: stepperType = StepperType.vertical);
}

In this widget, we can define the default stepper type as vertical, & the user can tap the floating action button, then the stepper will change from vertical to horizontal. When we run the app, we ought to get the output of the screen like the underneath screen capture.

Glance at the Code File

import 'package:flutter/material.dart';

class StepperDemo extends StatefulWidget {
@override
_StepperDemoState createState() => _StepperDemoState();
}

class _StepperDemoState extends State<StepperDemo> {
int _currentStep = 0;
StepperType stepperType = StepperType.vertical;


@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text('Flutter Stepper Demo'),
centerTitle: true,
),
body: Container(
child: Column(
children: [
Expanded(
child: Stepper(
type: stepperType,
physics: ScrollPhysics(),
currentStep: _currentStep,
onStepTapped: (step) => tapped(step),
onStepContinue: continued,
onStepCancel: cancel,
steps: <Step>[
Step(
title: new Text('Account'),
content: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: 'Email Address'),
),
TextFormField(
decoration: InputDecoration(labelText: 'Password'),
),
],
),
isActive: _currentStep >= 0,
state: _currentStep >= 0 ?
StepState.complete : StepState.disabled,
),
Step(
title: new Text('Address'),
content: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: 'Home Address'),
),
TextFormField(
decoration: InputDecoration(labelText: 'Postcode'),
),
],
),
isActive: _currentStep >= 0,
state: _currentStep >= 1 ?
StepState.complete : StepState.disabled,
),
Step(
title: new Text('Mobile Number'),
content: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: 'Mobile Number'),
),
],
),
isActive:_currentStep >= 0,
state: _currentStep >= 2 ?
StepState.complete : StepState.disabled,
),
],
),
),
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.list),
onPressed: switchStepsType,
),

);
}
switchStepsType() {
setState(() => stepperType == StepperType.vertical
? stepperType = StepperType.horizontal
: stepperType = StepperType.vertical);
}

tapped(int step){
setState(() => _currentStep = step);
}

continued(){
_currentStep < 2 ?
setState(() => _currentStep += 1): null;
}
cancel(){
_currentStep > 0 ?
setState(() => _currentStep -= 1) : null;
}
}

The Final Take:

In the blog, we’ve explained the basic structure of the Stepper Widget in a flutter. Though, you can simply modify this code as per your need and choice. Here we shared a small introduction to Stepper Widget On User Interaction from outside, & it’s working using Flutter.

We completely hope this blog will give you a good amount of detail on Trying up Stepper Widget in your coming Flutter projects. Although, if you are looking for a flutter app development agency that can help you to get a successful mobile app then Ionicfirebase is surely a good choice.

Why hire a dedicated flutter developer from Ionicfirebase?

Ionicfirebase, being a trustworthy mobile app development service provider, has won the heart of so many entrepreneurs and developers. They have so many mobile app developers that are dedicated to providing feature-rich mobile apps on time. Their development team’s main objective is to satisfy their valuable clients by simply keeping the focus on providing high-quality flutter mobile applications that match the requirements of their businesses. Feel free to connect with Ionicfirebase’s mobile application development team to get ready-made as well as on-demand apps at a reasonable rate.

Being a trustworthy flutter app development agency, Ionicfirebase has come to the list of top mobile app development agencies. Their development team’s every single developer goes through every single step of the process of mobile app development. Ionicfirebase is surely a worthy choice you can ever have especially if you are looking for ready-made and on-demand apps. So why wait? Just book an appointment with developers and get the app at a reasonable price. Hire dedicated flutter developers from Ionicfirebase, and get the app development service right now.

Clap 👏 If you like this article

Read my other blogs :

Follow Us On:

--

--

Ionic Firebase App
hireflutterdev

IonicFirebaseApp is the innovative marketplace for Mobile app, Web app, Backend on the newest trending technologies and tools. https://www.ionicfirebaseapp.com