Advertisement
Guest User

home

a guest
Oct 16th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.99 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'dart:math' as math;
  3.  
  4. void main() {
  5.   runApp(MaterialApp(
  6.     title: "Home",
  7.     home: Home_Screen(),
  8.     debugShowCheckedModeBanner: false,
  9.   ));
  10. }
  11.  
  12. class Home_Screen extends StatefulWidget {
  13.   @override
  14.   Home createState() => Home();
  15. }
  16.  
  17. class Home extends State<Home_Landing> with TickerProviderStateMixin {
  18.   AnimationController controller;
  19.  
  20.   String get timerString {
  21.     Duration duration = controller.duration * controller.value;
  22.     return '${duration.inMinutes}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
  23.   }
  24.  
  25.   @override
  26.   void initState() {
  27.     super.initState();
  28.     controller = AnimationController(
  29.       vsync: this,
  30.       duration: Duration(seconds: 30),
  31.     );
  32.   }
  33.  
  34.   @override
  35.   Widget build(BuildContext context) {
  36.     return Scaffold(
  37.       backgroundColor: Color(0xF5455A64),
  38.       body: AnimatedBuilder(
  39.           animation: controller,
  40.           builder: (context, child) {
  41.             return Stack(
  42.               children: <Widget>[
  43.                 Align(
  44.                   alignment: Alignment.topCenter,
  45.                   child: Container(
  46.                     height:
  47.                         controller.value * MediaQuery.of(context).size.height,
  48.                   ),
  49.                 ),
  50.                 Padding(
  51.                   padding: EdgeInsets.all(130.0),
  52.                   child: Column(
  53.                     mainAxisAlignment: MainAxisAlignment.spaceBetween,
  54.                     children: <Widget>[
  55.                       Expanded(
  56.                         child: Align(
  57.                           alignment: FractionalOffset.topCenter,
  58.                           child: AspectRatio(
  59.                             aspectRatio: 1.0,
  60.                             child: Stack(
  61.                               children: <Widget>[
  62.                                 Positioned.fill(
  63.                                   child: CustomPaint(
  64.                                       painter: CustomTimerPainter(
  65.                                           animation: controller,
  66.                                           backgroundColor: Colors.white,
  67.                                           color: Color(0xFF6889FF))),
  68.                                 ),
  69.                                 Align(
  70.                                   alignment: FractionalOffset.center,
  71.                                   child: Column(
  72.                                     mainAxisAlignment: MainAxisAlignment.center,
  73.                                     children: <Widget>[
  74.                                       Container(
  75.                                         child: Text(
  76.                                           timerString,
  77.                                           style: TextStyle(
  78.                                               fontSize: 30.0,
  79.                                               color: Colors.white),
  80.                                         ),
  81.                                       ),
  82.                                       Container(
  83.                                         child: Text(
  84.                                           "TakeTime",
  85.                                           style: TextStyle(
  86.                                               fontSize: 20.0,
  87.                                               color: Colors.white10),
  88.                                         ),
  89.                                       ),
  90.                                     ],
  91.                                   ),
  92.                                 ),
  93.                               ],
  94.                             ),
  95.                           ),
  96.                         ),
  97.                       ),
  98.                     ],
  99.                   ),
  100.                 ),
  101.  
  102.                 //box line
  103.                 AnimatedBuilder(
  104.                     animation: controller,
  105.                     builder: (context, child) {
  106.                       return Container(
  107.                         child: Padding(
  108.                           padding: EdgeInsets.all(50.0),
  109.                           child: new Container(
  110.                             width: 800.0,
  111.                             height: 200.0,
  112.                             child: new Container(
  113.                               decoration: new BoxDecoration(
  114.                                   border: new Border.all(
  115.                                       color: Color(0xFF4A4A4A),
  116.                                       width: 2.5,
  117.                                       style: BorderStyle.solid),
  118.                                   borderRadius: new BorderRadius.only(
  119.                                     topLeft: new Radius.circular(4.0),
  120.                                     topRight: new Radius.circular(4.0),
  121.                                     bottomRight: new Radius.circular(4.0),
  122.                                     bottomLeft: new Radius.circular(4.0),
  123.                                   )),
  124.                             ),
  125.                           ),
  126.                         ),
  127.                       );
  128.                     }),
  129.               ],
  130.             );
  131.           }),
  132.     );
  133.   }
  134. }
  135.  
  136. class CustomTimerPainter extends CustomPainter {
  137.   CustomTimerPainter({
  138.     this.animation,
  139.     this.backgroundColor,
  140.     this.color,
  141.   }) : super(repaint: animation);
  142.  
  143.   final Animation<double> animation;
  144.   final Color backgroundColor, color;
  145.  
  146.   @override
  147.   void paint(Canvas canvas, Size size) {
  148.     Paint paint = Paint()
  149.       ..color = backgroundColor
  150.       ..strokeWidth = 3.0
  151.       ..strokeCap = StrokeCap.butt
  152.       ..style = PaintingStyle.stroke;
  153.  
  154.     canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
  155.     paint.color = color;
  156.     double progress = (1.0 - animation.value) * 2 * math.pi;
  157.     canvas.drawArc(Offset.zero & size, math.pi * 1.5, -progress, false, paint);
  158.   }
  159.  
  160.   @override
  161.   bool shouldRepaint(CustomTimerPainter old) {
  162.     return animation.value != old.animation.value ||
  163.         color != old.color ||
  164.         backgroundColor != old.backgroundColor;
  165.   }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement