添加步骤
// 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,
),
];
Run Code Online (Sandbox Code Playgroud)
添加步进器
@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;
}
});
},
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
onStepTapped 将设置当前的步进器计数。onStepContinue 将递增步进计数器,并在我们的变量上调用 setState,将其设置为下一个计数器。onStepCancel 将减少步进计数器并返回到上一步。
完整代码
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;
}
});
},
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
六个月后。我将把它留在这里以备将来参考。不要使用步进器小部件来实现这一点。它相当僵硬。改用时间线小部件。时间轴瓷砖对我来说效果很好。https://pub.dev/packages/timeline_tile
归档时间: |
|
查看次数: |
4851 次 |
最近记录: |