Hibok
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

51 linhas
1.1 KiB

  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. class CounterOverlay extends StatefulWidget {
  4. @override
  5. CounterOverlayState createState() => CounterOverlayState();
  6. }
  7. class CounterOverlayState extends State<CounterOverlay>
  8. with TickerProviderStateMixin {
  9. Timer counter;
  10. int totalCount = 0;
  11. @override
  12. void initState() {
  13. super.initState();
  14. counter = Timer.periodic(Duration(seconds: 1), (Timer timer) {
  15. totalCount += 1;
  16. setState(() {});
  17. });
  18. }
  19. void hide() {
  20. counter.cancel();
  21. counter = null;
  22. }
  23. @override
  24. void dispose() {
  25. counter?.cancel();
  26. super.dispose();
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. int h = totalCount ~/ 3600;
  31. int m = (totalCount % 3600) ~/ 60;
  32. int s = totalCount % 60;
  33. var hStr = h >= 10 ? h.toString() : '0' + h.toString();
  34. var mStr = m >= 10 ? m.toString() : '0' + m.toString();
  35. var sStr = s >= 10 ? s.toString() : '0' + s.toString();
  36. return Text('$hStr:$mStr:$sStr',
  37. textScaleFactor: 1.0,
  38. style: TextStyle(color: Colors.white, fontSize: 30));
  39. }
  40. }