Six months later. I'll just leave this here for future reference. Don't use the stepper widget to achieve that. It's quite rigid. Use a timeline widget instead. Timeline tile has worked well for me. https://pub.dev/packages/timeline_tile
Add the Steps
// Step Counter
int current_step = 0;
List<Step> steps = [
Step(
title: Text('Step 1'),
content: Text('Hello!'),
isActive: true,
),
Step(
title: Text('Step 2'),
content: Text('World!'),
isActive: true,
),
Step(
title: Text('Step 3'),
content: Text('Hello World!'),
state: StepState.complete,
isActive: true,
),
];
Add Stepper
@override
Widget build(BuildContext context) {
return Scaffold(
// Appbar
appBar: AppBar(
// Title
title: Text("Simple Stepper Demo"),
),
// Body
body: Container(
child: Stepper(
currentStep: this.current_step,
steps: steps,
type: StepperType.vertical,
onStepTapped: (step) {
setState(() {
current_step = step;
});
},
onStepContinue: () {
setState(() {
if (current_step < steps.length - 1) {
current_step = current_step + 1;
} else {
current_step = 0;
}
});
},
onStepCancel: () {
setState(() {
if (current_step > 0) {
current_step = current_step - 1;
} else {
current_step = 0;
}
});
},
),
),
);
}
onStepTapped will set the current stepper count. onStepContinue will increment the stepper Counter and setState is called on our variable that sets it to the next counter. onStepCancel will decrement the stepper counter and moves back to the previous step.
Complete Code
import 'package:flutter/material.dart';
class StepperDemo extends StatefulWidget {
StepperDemo() : super();
final String title = "Stepper Demo";
@override
StepperDemoState createState() => StepperDemoState();
}
class StepperDemoState extends State<StepperDemo> {
//
int current_step = 0;
List<Step> steps = [
Step(
title: Text('Step 1'),
content: Text('Hello!'),
isActive: true,
),
Step(
title: Text('Step 2'),
content: Text('World!'),
isActive: true,
),
Step(
title: Text('Step 3'),
content: Text('Hello World!'),
state: StepState.complete,
isActive: true,
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
// Appbar
appBar: AppBar(
// Title
title: Text("Simple Stepper Demo"),
),
// Body
body: Container(
child: Stepper(
currentStep: this.current_step,
steps: steps,
type: StepperType.vertical,
onStepTapped: (step) {
setState(() {
current_step = step;
});
},
onStepContinue: () {
setState(() {
if (current_step < steps.length - 1) {
current_step = current_step + 1;
} else {
current_step = 0;
}
});
},
onStepCancel: () {
setState(() {
if (current_step > 0) {
current_step = current_step - 1;
} else {
current_step = 0;
}
});
},
),
),
);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.