-
-
Save MestreKarin/f57926b072c7f2d6abc0fec52977711c to your computer and use it in GitHub Desktop.
Circular Count Down Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:circular_countdown_timer/circular_countdown_timer.dart'; | |
class ScreenData { | |
final String title; | |
final String subtitle; | |
final String image; | |
final int duration; | |
ScreenData._({ | |
required this.title, | |
required this.subtitle, | |
required this.image, | |
required this.duration | |
}); | |
factory ScreenData(String title, String subtitle, String image, int duration) => ScreenData._( | |
title: title, | |
subtitle: subtitle, | |
image: image, | |
duration: duration | |
); | |
} | |
class CircularPage extends StatefulWidget { | |
@override | |
_CircularPageState createState() => _CircularPageState(); | |
} | |
class _CircularPageState extends State<CircularPage> { | |
final CountDownController _controller = CountDownController(); | |
final List<ScreenData> _data = [ | |
ScreenData("Saltar à corda", "Próximo: Subir à cadeira", "assets/images/1.gif", 15), | |
ScreenData("Subir à cadeira", "Próximo: Flexões", "assets/images/2.gif", 10), | |
ScreenData("Flexões", "Próximo: Abdominais", "assets/images/1.gif", 10), | |
ScreenData("Abdominais", "Próximo: Prancha", "assets/images/2.gif", 10), | |
ScreenData("Prancha", "", "assets/images/1.gif", 25), | |
]; | |
int _currentIndex = 0; | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Padding( | |
padding: EdgeInsets.all(20.0), | |
child: Column( | |
mainAxisSize: MainAxisSize.max, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
_buildData(), | |
SizedBox(height: 64), | |
_buildTimer(), | |
SizedBox(height: 64), | |
_buildControls() | |
], | |
), | |
), | |
); | |
} | |
Widget _buildData() { | |
final d = _data[_currentIndex]; | |
return Column( | |
children: [ | |
Image( | |
image: AssetImage(d.image), | |
height: 88, | |
), | |
SizedBox(height: 24), | |
Text( | |
d.title, | |
style: TextStyle( | |
color: Colors.grey.shade800, | |
fontSize: 20 | |
), | |
), | |
SizedBox(height: 16), | |
d.subtitle.isEmpty ? SizedBox.shrink() : Text( | |
d.subtitle, | |
style: TextStyle( | |
color: Colors.grey[350], | |
fontSize: 16 | |
), | |
), | |
], | |
); | |
} | |
Widget _buildControls() { | |
return Row( | |
children: [ | |
ElevatedButton( | |
onPressed: () { | |
setState(() { | |
if (++_currentIndex >= _data.length) { | |
_currentIndex = 0; | |
} | |
}); | |
_controller.restart(duration: _data[_currentIndex].duration); | |
}, | |
child: Text('Próximo') | |
) | |
], | |
); | |
} | |
Widget _buildTimer() { | |
return CircularCountDownTimer( | |
controller: _controller, | |
width: MediaQuery.of(context).size.width / 5, | |
height: MediaQuery.of(context).size.height / 5, | |
duration: _data[_currentIndex].duration, | |
fillColor: Colors.red, | |
ringColor: Colors.white, | |
backgroundColor: null, | |
isReverse: true, | |
isReverseAnimation: true, | |
isTimerTextShown: true, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment