Flutter Open
  • Flutter Widgets
  • Structure of code
  • Widgets 01 | Container
  • Widgets 02 | Text
  • Widgets 03 | Image
  • Widgets 04 | Row & Column
  • Widgets 05 | Icon
  • Widgets 06 | RaiseButton
  • Widgets 07 | AppBar
  • Widgets 08 | Scaffold
  • Widgets 09 | FlutterLogo
  • Widgets 10 | Placeholder
  • Widgets 11 | BottomNavigationBar
  • Widgets 12 | TabBarView&TabBar
  • Widgets 13 | DropdownButton
  • Widgets 14 | PopupMenuButton
  • Widgets 15 | Stack
  • Widgets 16 | Stepper
  • Widgets 17 | SimpleDialog
  • Widgets 18 | SnackBar
  • Animation
    • Animation 01 | Base Animation
    • Animation 02 | Flare Animation
  • Canvas
    • Canvas 01 | Custom Painting
    • Canvas 02 | Round Angle Polygon
    • Canvas 03 | Regular Polygon
    • Canvas 04 | Pie Chart With Round Angle
    • Canvas 05 | Gesture With Canvas
Powered by GitBook
On this page
  • Before Start
  • Simple Use
  • Constructor
  • steps
  • type
  • onStepTapped&currentStep
  • controlsBuilder
  • Conclusion

Was this helpful?

Widgets 16 | Stepper

In this tutorial, you will learn how to use the Stepper in the flutter.

Before Start

We should create a page to contain our code.

import "package:flutter/material.dart";
import 'package:flutter_widgets/const/_const.dart';

class StepperPage extends StatefulWidget {
  @override
  _StepperState createState() => _StepperState();
}

class _StepperState extends State<StepperPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(PageName.STEPPER),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            //our code.
            SizedBox(height: 600)
          ],
        ),
      ),
    );
  }
}

It shows an empty page with a title.

Simple Use

When I write this article, I have used some steps to describe our tutorials. In this situation, we can use a stepper to implement this.

 Container(
              color: RED,
              child: Stepper(
                steps: [
                  Step(
                    title: Text("Start"),
                    content: Text("Before starting, we should create a page."),
                  ),
                  Step(
                    title: Text("Constructor"),
                    content: Text("Let's look at its construtor."),
                  ),
                ],
              ),
            ),

It will show as follows.

Constructor

Let's look at its constructor. The steps is a list, onStepTapped, onStepContinue, onStepCancel,controlsBuilder are functions. The currentStep is the int. The type is the enum. I will tell the detail of them one by one.

Stepper({
    Key key,
    @required this.steps,
    this.type = StepperType.vertical,
    this.currentStep = 0,
    this.onStepTapped,
    this.onStepContinue,
    this.onStepCancel,
    this.controlsBuilder,
  })

steps

Let's look at the definition of the steps.

  final List<Step> steps;

Its constructor is below.

Step({
    @required this.title,
    this.subtitle,
    @required this.content,
    this.state = StepState.indexed,
    this.isActive = false,
  })

The title, subtitle, content are the widgets, the state is an enum.

So let's see an example.

Widget _steps() => Container(
        margin: EdgeInsets.only(top: 10),
        color: GREEN,
        child: Stepper(
          steps: [
            Step(
              title: Text("First"),
              subtitle: Text("This is our first article"),
              content: Text(
                  "In this article, I will tell you how to create a page."),
            ),
            Step(
                title: Text("Second"),
                subtitle: Text("Constructor"),
                content: Text("Let's look at its construtor."),
                state: StepState.editing,
                isActive: true),
            Step(
                title: Text("Third"),
                subtitle: Text("Constructor"),
                content: Text("Let's look at its construtor."),
                state: StepState.error),
          ],
        ),
      );

It will show you like this.

type

It has two types, the default value is the vertical. We use the horizontal in this example.

 Widget _typeStep() => Container(
        margin: EdgeInsets.only(top: 10),
        constraints: BoxConstraints.expand(height: 200),
        color: BLUE_LIGHT,
        child: Stepper(
          type: StepperType.horizontal,
          steps: [
            Step(
              title: Text("First"),
              content: Text("This is our first example."),
            ),
            Step(
              title: Text("Second"),
              content: Text("This is our second example."),
            ),
          ],
        ),
      );

It shows as follows.

onStepTapped&currentStep

In the fore example, when we click the second title, it doesn't show the content of the second. We need some handle.

 Widget _tabStep() => Container(
        margin: EdgeInsets.only(top: 10),
        color: PURPLE,
        child: Stepper(
          steps: [
            Step(
              title: Text("First"),
              content: Text("This is our first example."),
            ),
            Step(
              title: Text("Second"),
              content: Text("This is our second example."),
            ),
            Step(
              title: Text("Third"),
              content: Text("This is our third example."),
            ),
            Step(
              title: Text("Forth"),
              content: Text("This is our forth example."),
            ),
          ],
          currentStep: _index,
          onStepTapped: (index) {
            setState(() {
              _index = index;
            });
          },
          onStepCancel: () {
            print("You are clicking the cancel button.");
          },
          onStepContinue: () {
            print("You are clicking the continue button.");
          },
        ),
      );

When you click the third title, it will show as follows.

When you click the continue or cancel, it will print as follows.

I/flutter ( 6888): You are clicking the continue button.
I/flutter ( 6888): You are clicking the cancel button.

controlsBuilder

If you want to custom your own continue, cancel button, you can use the controlsBuilder to define them. The function is the same as the above. But this time, I will hide these two buttons.

 Widget _builderStep() => Container(
        margin: EdgeInsets.only(top: 10),
        color: PURPLE,
        child: Stepper(
          steps: [
            Step(
              title: Text("First"),
              content: Text("This is our first example."),
            ),
            Step(
              title: Text("Second"),
              content: Text("This is our second example."),
            ),
            Step(
              title: Text("Third"),
              content: Text("This is our third example."),
            ),
            Step(
              title: Text("Forth"),
              content: Text("This is our forth example."),
            ),
          ],
          currentStep: _index,
          onStepTapped: (index) {
            setState(() {
              _index = index;
            });
          },
          controlsBuilder: (BuildContext context,
                  {VoidCallback onStepContinue, VoidCallback onStepCancel}) =>
              Container(),
        ),
      );

It will hide these two buttons.

Conclusion

Today, we have learned the Stepper. It has many parameters, the most thing you should know that this widget is very special widget. You can learn it when you need time.

Thanks for your reading!

The end.

Facebook Page

Twitter

GitHub

Medium

PreviousWidgets 15 | StackNextWidgets 17 | SimpleDialog

Last updated 6 years ago

Was this helpful?

Whole code in ,star to support.

GitHub
Flutter Open
NieBin
NieBin
FlutterOpen