import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green, // Set the app's primary theme color
),
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// Variable to store the progress value
double progress = 0.0;
// Method to update the progress value
// and trigger a UI rebuild
void updateProgress(double value) {
setState(() {
progress = value;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Line ProgressBar with CardView'),
),
body: Center(
child: Card(
elevation: 5.0,
margin: EdgeInsets.all(16.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// LinearProgressIndicator to
// visually represent progress
LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey,
valueColor: AlwaysStoppedAnimation<Color>(Colors.green),
),
SizedBox(height: 16.0),
// Row containing buttons to control the progress
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// Button to decrease progress
ElevatedButton(
onPressed: () {
if (progress > 0) {
updateProgress(progress - 0.1);
}
},
child: Text('Decrease'),
),
// Button to increase progress
ElevatedButton(
onPressed: () {
if (progress < 1.0) {
updateProgress(progress + 0.1);
}
},
child: Text('Increase'),
),
// Button to reset progress to zero
ElevatedButton(
onPressed: () {
updateProgress(0.0);
},
child: Text('Reset'),
),
],
),
],
),
),
),
),
);
}
}