countdown_progress_indicator 0.1.1 countdown_progress_indicator: ^0.1.1 copied to clipboard
Customizable countdown timer for Flutter with pause/resume controls.
import 'package:countdown_progress_indicator/countdown_progress_indicator.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isRunning = true;
final _controller = CountDownController();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
color: Colors.white,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 200,
width: 200,
child: CountDownProgressIndicator(
controller: _controller,
valueColor: Colors.red,
backgroundColor: Colors.blue,
initialPosition: 0,
duration: 20,
text: 'SEC',
onComplete: () => null,
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () => setState(() {
if (_isRunning) {
_controller.pause();
} else {
_controller.resume();
}
_isRunning = !_isRunning;
}),
child: Text(_isRunning ? 'Pause' : 'Resume'),
)
],
),
),
),
),
);
}
}