Guest User

Untitled

a guest
Mar 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. import 'dart:math' as math;
  2. import 'package:meta/meta.dart';
  3. import 'package:flutter/material.dart';
  4.  
  5. void main() {
  6. runApp(new MaterialApp(
  7. theme: new ThemeData(
  8. canvasColor: Colors.deepPurple,
  9. iconTheme: new IconThemeData(color: Colors.white),
  10. accentColor: Colors.pinkAccent,
  11. brightness: Brightness.dark,
  12. ),
  13. home: new MyHomePage(),
  14. ));
  15. }
  16.  
  17. class ProgressPainter extends CustomPainter {
  18. ProgressPainter({
  19. @required this.animation,
  20. @required this.backgroundColor,
  21. @required this.color,
  22. }) : super(repaint: animation);
  23.  
  24. /// Animation representing what we are painting
  25. final Animation<double> animation;
  26.  
  27. /// The color in the background of the circle
  28. final Color backgroundColor;
  29.  
  30. /// The foreground color used to indicate progress
  31. final Color color;
  32.  
  33. @override
  34. void paint(Canvas canvas, Size size) {
  35. Paint paint = new Paint()
  36. ..color = backgroundColor
  37. ..strokeWidth = 5.0
  38. ..strokeCap = StrokeCap.round
  39. ..style = PaintingStyle.stroke;
  40. canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
  41. paint.color = color;
  42. double progressRadians = (1.0 - animation.value) * 2 * math.PI;
  43. canvas.drawArc(
  44. Offset.zero & size, math.PI * 1.5, -progressRadians, false, paint);
  45. }
  46.  
  47. @override
  48. bool shouldRepaint(ProgressPainter other) {
  49. return animation.value != other.animation.value ||
  50. color != other.color ||
  51. backgroundColor != other.backgroundColor;
  52. }
  53. }
  54.  
  55. class MyHomePage extends StatefulWidget {
  56. _MyHomePageState createState() => new _MyHomePageState();
  57. }
  58.  
  59. class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  60. List<IconData> icons = <IconData>[
  61. Icons.alarm, Icons.access_time, Icons.hourglass_empty, Icons.timer,
  62. ];
  63.  
  64. AnimationController _controller;
  65.  
  66. String get timeRemaining {
  67. Duration duration = _controller.duration * _controller.value;
  68. return '${duration.inMinutes} ${(duration.inSeconds % 60)
  69. .toString()
  70. .padLeft(2, '0')}';
  71. }
  72.  
  73. @override
  74. void initState() {
  75. super.initState();
  76. _controller = new AnimationController(
  77. vsync: this,
  78. duration: const Duration(seconds: 12),
  79. )
  80. ..reverse(from: 0.4);
  81. }
  82.  
  83. Widget build(BuildContext context) {
  84. ThemeData themeData = Theme.of(context);
  85. return new Scaffold(
  86. body: new Padding(
  87. padding: const EdgeInsets.all(10.0),
  88. child:
  89. new Column(
  90. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  91. children: <Widget>[
  92. new Row(
  93. mainAxisAlignment: MainAxisAlignment.start,
  94. children: icons.map((IconData iconData) {
  95. return new Container(
  96. margin: new EdgeInsets.all(10.0),
  97. child: new IconButton(
  98. icon: new Icon(iconData), onPressed: () {
  99. // TODO: Implement
  100. }),
  101. );
  102. }).toList(),
  103. ),
  104. new Expanded(
  105. child: new Align(
  106. alignment: FractionalOffset.center,
  107. child: new AspectRatio(
  108. aspectRatio: 1.0,
  109. child: new Stack(
  110. children: <Widget>[
  111. new Positioned.fill(
  112. child: new AnimatedBuilder(
  113. animation: _controller,
  114. builder: (BuildContext context, Widget child) {
  115. return new CustomPaint(
  116. painter: new ProgressPainter(
  117. animation: _controller,
  118. color: themeData.indicatorColor,
  119. backgroundColor: Colors.white,
  120. ),
  121. );
  122. }
  123. ),
  124. ),
  125. new Align(
  126. alignment: FractionalOffset.center,
  127. child: new Column(
  128. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  129. crossAxisAlignment: CrossAxisAlignment.center,
  130. children: <Widget>[
  131. new Text(
  132. 'Label', style: themeData.textTheme.subhead),
  133. new AnimatedBuilder(
  134. animation: _controller,
  135. builder: (BuildContext context, Widget child) {
  136. return new Text(
  137. timeRemaining,
  138. style: themeData.textTheme.display4,
  139. );
  140. }
  141. ),
  142. new Text('+1', style: themeData.textTheme.title),
  143. ],
  144. ),
  145. ),
  146. ],
  147. ),
  148. ),
  149. ),
  150. ),
  151. new Container(
  152. margin: new EdgeInsets.all(10.0),
  153. child: new Row(
  154. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  155. children: <Widget>[
  156. new IconButton(icon: new Icon(Icons.delete), onPressed: () {
  157. // TODO: Implement delete
  158. }),
  159. new FloatingActionButton(
  160. child: new AnimatedBuilder(
  161. animation: _controller,
  162. builder: (BuildContext context, Widget child) {
  163. return new Icon(
  164. _controller.isAnimating
  165. ? Icons.pause
  166. : Icons.play_arrow
  167. );
  168. },
  169. ),
  170. onPressed: () {
  171. if (_controller.isAnimating)
  172. _controller.stop();
  173. else {
  174. _controller.reverse(
  175. from: _controller.value == 0.0 ? 1.0 : _controller
  176. .value,
  177. );
  178. }
  179. },
  180. ),
  181. new IconButton(
  182. icon: new Icon(Icons.alarm_add), onPressed: () {
  183. // TODO: Implement add time
  184. }),
  185. ],
  186. ),
  187. ),
  188. ],
  189. ),
  190. ),
  191. );
  192. }
  193. }
Add Comment
Please, Sign In to add comment