如何显示进度条以在Flutter中更新交付 [英] how to show Progress Bar for delivery updation in flutter
本文介绍了如何显示进度条以在Flutter中更新交付的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的应用程序中添加进度条,但我不知道该怎么做.我只是个入门者,想学习如何添加进度条i n交付应用程序
i wanna add a progress bar in my app but i dont know how to do this thing. i just a beginer for flutter and wanna learn how to add progress bar in delivery Application
推荐答案
添加步骤
// 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,
),
];
添加步进器
@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将设置当前步进数.onStepContinue将递增步进计数器,并在将其设置为下一个计数器的变量上调用setState.onStepCancel将使步进计数器递减并返回上一步.
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.
完整代码
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;
}
});
},
),
),
);
}
}
这篇关于如何显示进度条以在Flutter中更新交付的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文