import 'dart:async';

import 'package:flutter/material.dart';

class CounterOverlay extends StatefulWidget {
  @override
  CounterOverlayState createState() => CounterOverlayState();
}

class CounterOverlayState extends State<CounterOverlay>
    with TickerProviderStateMixin {
  Timer counter;
  int totalCount = 0;

  @override
  void initState() {
    super.initState();

    counter = Timer.periodic(Duration(seconds: 1), (Timer timer) {
      totalCount += 1;
      setState(() {});
    });
  }

  void hide() {
    counter.cancel();
    counter = null;
  }

  @override
  void dispose() {
    counter?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {

    int h = totalCount ~/ 3600;
    int m = (totalCount % 3600) ~/ 60;
    int s = totalCount % 60;

    var hStr = h >= 10 ? h.toString() : '0' + h.toString();
    var mStr = m >= 10 ? m.toString() : '0' + m.toString();
    var sStr = s >= 10 ? s.toString() : '0' + s.toString();
    return Text('$hStr:$mStr:$sStr',
        textScaleFactor: 1.0,
        style: TextStyle(color: Colors.white, fontSize: 30));
  }
}
