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
We can show the progress by specifying the value between 0.0 and 1.0. An indeterminate progress bar is used when we do not want to know the percentage of an ongoing process. By default, CircularProgressIndicator shows the indeterminate progress bar.
You just need to make bool if its loading and getting data, the indicator shows up.
Flutter provides a class called CircularProgressIndicator. To create a circular progress indicator we have to call its constructor. There are no required properties for this widget so we can directly call the constructor.
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;
}
});
},
),
),
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With