Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'dart:math' as math;
- void main() {
- runApp(MaterialApp(
- title: "Home",
- home: Home_Screen(),
- debugShowCheckedModeBanner: false,
- ));
- }
- class Home_Screen extends StatefulWidget {
- @override
- Home createState() => Home();
- }
- class Home extends State<Home_Landing> with TickerProviderStateMixin {
- AnimationController controller;
- String get timerString {
- Duration duration = controller.duration * controller.value;
- return '${duration.inMinutes}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
- }
- @override
- void initState() {
- super.initState();
- controller = AnimationController(
- vsync: this,
- duration: Duration(seconds: 30),
- );
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Color(0xF5455A64),
- body: AnimatedBuilder(
- animation: controller,
- builder: (context, child) {
- return Stack(
- children: <Widget>[
- Align(
- alignment: Alignment.topCenter,
- child: Container(
- height:
- controller.value * MediaQuery.of(context).size.height,
- ),
- ),
- Padding(
- padding: EdgeInsets.all(130.0),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Expanded(
- child: Align(
- alignment: FractionalOffset.topCenter,
- child: AspectRatio(
- aspectRatio: 1.0,
- child: Stack(
- children: <Widget>[
- Positioned.fill(
- child: CustomPaint(
- painter: CustomTimerPainter(
- animation: controller,
- backgroundColor: Colors.white,
- color: Color(0xFF6889FF))),
- ),
- Align(
- alignment: FractionalOffset.center,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- child: Text(
- timerString,
- style: TextStyle(
- fontSize: 30.0,
- color: Colors.white),
- ),
- ),
- Container(
- child: Text(
- "TakeTime",
- style: TextStyle(
- fontSize: 20.0,
- color: Colors.white10),
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- //box line
- AnimatedBuilder(
- animation: controller,
- builder: (context, child) {
- return Container(
- child: Padding(
- padding: EdgeInsets.all(50.0),
- child: new Container(
- width: 800.0,
- height: 200.0,
- child: new Container(
- decoration: new BoxDecoration(
- border: new Border.all(
- color: Color(0xFF4A4A4A),
- width: 2.5,
- style: BorderStyle.solid),
- borderRadius: new BorderRadius.only(
- topLeft: new Radius.circular(4.0),
- topRight: new Radius.circular(4.0),
- bottomRight: new Radius.circular(4.0),
- bottomLeft: new Radius.circular(4.0),
- )),
- ),
- ),
- ),
- );
- }),
- ],
- );
- }),
- );
- }
- }
- class CustomTimerPainter extends CustomPainter {
- CustomTimerPainter({
- this.animation,
- this.backgroundColor,
- this.color,
- }) : super(repaint: animation);
- final Animation<double> animation;
- final Color backgroundColor, color;
- @override
- void paint(Canvas canvas, Size size) {
- Paint paint = Paint()
- ..color = backgroundColor
- ..strokeWidth = 3.0
- ..strokeCap = StrokeCap.butt
- ..style = PaintingStyle.stroke;
- canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
- paint.color = color;
- double progress = (1.0 - animation.value) * 2 * math.pi;
- canvas.drawArc(Offset.zero & size, math.pi * 1.5, -progress, false, paint);
- }
- @override
- bool shouldRepaint(CustomTimerPainter old) {
- return animation.value != old.animation.value ||
- color != old.color ||
- backgroundColor != old.backgroundColor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement