Last active
August 10, 2021 22:05
-
-
Save funwithflutter/c1838c8ac832a9e4935ccd7f516b9fe0 to your computer and use it in GitHub Desktop.
Revisions
-
funwithflutter revised this gist
Aug 10, 2021 . 1 changed file with 15 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,19 +2,21 @@ import 'dart:math'; import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( showPerformanceOverlay: false, title: 'Paint Demo', home: Scaffold( appBar: AppBar( title: const Text('Paint Demo'), ), body: const Center( child: PaintDemo(), ), ), @@ -23,21 +25,21 @@ class MyApp extends StatelessWidget { } class PaintDemo extends StatefulWidget { const PaintDemo({Key? key}) : super(key: key); @override _PaintDemoState createState() => _PaintDemoState(); } class _PaintDemoState extends State<PaintDemo> with SingleTickerProviderStateMixin { late AnimationController _controller; late CurvedAnimation _animation; @override void initState() { _controller = AnimationController(vsync: this, duration: const Duration(seconds: 3)); _animation = CurvedAnimation(parent: _controller, curve: Curves.slowMiddle); _controller.repeat(); @@ -60,7 +62,7 @@ class _PaintDemoState extends State<PaintDemo> child: child, ); }, child: const SizedBox( width: 200, height: 75, child: Text('Loading...'), @@ -75,7 +77,7 @@ class LinePainter extends CustomPainter { final double progress; static final linePaint = Paint() ..color = const Color(0xFFF4AC45) ..style = PaintingStyle.stroke ..strokeWidth = 6 ..strokeCap = StrokeCap.round; @@ -90,9 +92,9 @@ class LinePainter extends CustomPainter { final point1 = max(0.0, widthProgress - _gap); final point2 = min(widthProgress + _gap, size.width); canvas ..drawLine(Offset(0, height), Offset(point1, height), linePaint) ..drawLine(Offset(point2, height), Offset(size.width, height), linePaint); } @override @@ -102,4 +104,4 @@ class LinePainter extends CustomPainter { } return false; } } -
funwithflutter revised this gist
Feb 28, 2020 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -44,6 +44,12 @@ class _PaintDemoState extends State<PaintDemo> super.initState(); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return AnimatedBuilder( @@ -96,4 +102,4 @@ class LinePainter extends CustomPainter { } return false; } } -
funwithflutter created this gist
Feb 28, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,99 @@ import 'dart:math'; import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( showPerformanceOverlay: false, title: 'Paint Demo', home: Scaffold( appBar: AppBar( title: Text('Paint Demo'), ), body: Center( child: PaintDemo(), ), ), ); } } class PaintDemo extends StatefulWidget { PaintDemo({Key key}) : super(key: key); @override _PaintDemoState createState() => _PaintDemoState(); } class _PaintDemoState extends State<PaintDemo> with SingleTickerProviderStateMixin { AnimationController _controller; CurvedAnimation _animation; @override void initState() { _controller = AnimationController(vsync: this, duration: Duration(seconds: 3)); _animation = CurvedAnimation(parent: _controller, curve: Curves.slowMiddle); _controller.repeat(); super.initState(); } @override Widget build(BuildContext context) { return AnimatedBuilder( animation: _animation, builder: (_, child) { return CustomPaint( painter: LinePainter(progress: _animation.value), child: child, ); }, child: Container( width: 200, height: 75, child: Text('Loading...'), ), ); } } class LinePainter extends CustomPainter { LinePainter({this.progress = 0.5}); final double progress; static final linePaint = Paint() ..color = Color(0xFFF4AC45) ..style = PaintingStyle.stroke ..strokeWidth = 6 ..strokeCap = StrokeCap.round; static const _gap = 12.0; @override void paint(Canvas canvas, Size size) { final height = size.height / 2; final widthProgress = size.width * progress; final point1 = max(0.0, widthProgress - _gap); final point2 = min(widthProgress + _gap, size.width); canvas.drawLine(Offset(0, height), Offset(point1, height), linePaint); canvas.drawLine( Offset(point2, height), Offset(size.width, height), linePaint); } @override bool shouldRepaint(LinePainter oldDelegate) { if (progress != oldDelegate.progress) { return true; } return false; } }