0

I just want to Start Auction app for this I need a timer I searched in YouTube got the link https://www.youtube.com/watch?v=Rkkb8P9LsPw&t=121s but its weird I Just need this content only can someone help this Code is here https://github.com/tadaspetra/bookclub/tree/INTEGRATION_BUILD_0_1/book_club

I need this part alone

enter image description here

LonelyWolf
  • 4,164
  • 16
  • 36
MGR DR
  • 203
  • 1
  • 2
  • 7
  • have you done something or do you want us to code for you ? In case of first, Please show us what you have achieved so far so that we can help you, In case you want the second, this may not be the place to ask – Vilsad P P Jun 28 '20 at 06:31

1 Answers1

1

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:

tnc1997
  • 1,832
  • 19
  • 20