Horizontal Progress Bar Linear Progress Indicator
Complete Code For Horizontal Progress Bar Linear Progress Indicator In Flutter
main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
backgroundColor: Color(0xFF43A047),
title: Text('Horizontal Progress Bar')
),
body: Center(
child: Progress()
)
)
);
}
}
class Progress extends StatefulWidget {
@override
ProgressState createState() => new ProgressState();
}
class ProgressState extends State<Progress>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation animation;
double beginAnim = 0.0 ;
double endAnim = 1.0 ;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(seconds: 5), vsync: this);
animation = Tween(begin: beginAnim, end: endAnim).animate(controller)
..addListener(() {
setState(() {
// Change here any Animation object value.
});
});
}
@override
void dispose() {
controller.stop();
super.dispose();
}
startProgress(){
controller.forward();
}
stopProgress(){
controller.stop();
}
resetProgress(){
controller.reset();
}
@override
Widget build(BuildContext context) {
return Center(
child: Column(children: [
Container(
padding: EdgeInsets.all(20.0),
child: LinearProgressIndicator(
value: animation.value,
)),
RaisedButton(
child: Text(" Start Progress "),
onPressed: startProgress,
color: Color(0xFF43A047),
textColor: Colors.white,
splashColor: Colors.grey,
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
),
RaisedButton(
child: Text(" Stop Progress "),
onPressed: stopProgress,
color: Color(0xFF43A047),
textColor: Colors.white,
splashColor: Colors.grey,
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
),
RaisedButton(
child: Text(" Reset Progress "),
onPressed: resetProgress,
color: Color(0xFF43A047),
textColor: Colors.white,
splashColor: Colors.grey,
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
)
]
));
}
}