Without seeing your code, it is difficult to understand exactly what you are looking for, however the example below could be used as a starting point for a basic countdown timer:
import 'dart:async';
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
DateTime _now;
DateTime _auction;
Timer _timer;
@override
Widget build(BuildContext context) {
// Calculates the difference between the auction date time and the current date time.
final difference = _auction.difference(_now);
return Scaffold(
body: Center(
child: Card(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('${difference.inHours} hours'),
Text('${difference.inMinutes.remainder(60)} minutes'),
Text('${difference.inSeconds.remainder(60)} seconds'),
],
),
),
),
);
}
@override
void dispose() {
// Cancels the timer when the page is disposed.
_timer.cancel();
super.dispose();
}
@override
void initState() {
super.initState();
// Sets the current date time.
_now = DateTime.now();
// Sets the date time of the auction.
_auction = _now.add(Duration(days: 1));
// Creates a timer that fires every second.
_timer = Timer.periodic(
Duration(
seconds: 1,
),
(timer) {
setState(() {
// Updates the current date time.
_now = DateTime.now();
// If the auction has now taken place, then cancels the timer.
if (_auction.isBefore(_now)) {
timer.cancel();
}
});
},
);
}
}
This answer takes inspiration from the below questions and I would recommend that you take a look at them for more information regarding your question: