flutter_pausable_countdown_timer 1.0.0 flutter_pausable_countdown_timer: ^1.0.0 copied to clipboard
It is a simple pausable countdown timer.
import 'package:flutter/material.dart';
import 'package:flutter_pausable_countdown_timer/flutter_pausable_countdown_timer.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Timer Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Timer Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Timer that stops when tapped.',
style: TextStyle(fontSize: 24),
),
Container(
margin: const EdgeInsets.all(50),
child: CountdownTimer(
seconds: 1000,
textStyle:
const TextStyle(fontSize: 100, fontWeight: FontWeight.bold),
pauseAction: () {
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
title: const Text(
'pause!',
textAlign: TextAlign.center,
),
),
);
},
restartAction: () {
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
title: const Text(
'restart!',
textAlign: TextAlign.center,
),
),
);
},
),
),
],
),
),
);
}
}