Created
January 13, 2021 08:16
-
-
Save ShaiqAhmedkhan/b4c41a30004d6275b97fc0a4c70106ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment