From bde7c68efb43a777641bdecd649b76843286576f Mon Sep 17 00:00:00 2001 From: SirDank <52797753+SirDank@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:46:13 +0530 Subject: [PATCH 1/2] Update border_beam.dart - format --- lib/fx_7_border_beam/border_beam.dart | 51 +++++++++++++-------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/lib/fx_7_border_beam/border_beam.dart b/lib/fx_7_border_beam/border_beam.dart index fcaeee6..712af67 100644 --- a/lib/fx_7_border_beam/border_beam.dart +++ b/lib/fx_7_border_beam/border_beam.dart @@ -1,19 +1,9 @@ import 'package:flutter/material.dart'; -import 'dart:math' as math; import 'dart:ui' as ui; class BorderBeam extends StatefulWidget { - final Widget child; - final double duration; - final double borderWidth; - final Color colorFrom; - final Color colorTo; - final Color staticBorderColor; - final BorderRadius borderRadius; - final EdgeInsetsGeometry padding; - const BorderBeam({ - Key? key, + super.key, required this.child, this.duration = 15, this.borderWidth = 1.5, @@ -22,7 +12,16 @@ class BorderBeam extends StatefulWidget { this.staticBorderColor = const Color(0xFFCCCCCC), this.borderRadius = const BorderRadius.all(Radius.circular(12)), this.padding = EdgeInsets.zero, - }) : super(key: key); + }); + + final BorderRadius borderRadius; + final double borderWidth; + final Widget child; + final Color colorFrom; + final Color colorTo; + final double duration; + final EdgeInsetsGeometry padding; + final Color staticBorderColor; @override _BorderBeamState createState() => _BorderBeamState(); @@ -30,8 +29,14 @@ class BorderBeam extends StatefulWidget { class _BorderBeamState extends State with SingleTickerProviderStateMixin { - late AnimationController _controller; late Animation _animation; + late AnimationController _controller; + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } @override void initState() { @@ -44,12 +49,6 @@ class _BorderBeamState extends State _controller.repeat(); } - @override - void dispose() { - _controller.dispose(); - super.dispose(); - } - @override Widget build(BuildContext context) { return AnimatedBuilder( @@ -75,13 +74,6 @@ class _BorderBeamState extends State } class BorderBeamPainter extends CustomPainter { - final double progress; - final double borderWidth; - final Color colorFrom; - final Color colorTo; - final Color staticBorderColor; - final BorderRadius borderRadius; - BorderBeamPainter({ required this.progress, required this.borderWidth, @@ -91,6 +83,13 @@ class BorderBeamPainter extends CustomPainter { required this.borderRadius, }); + final BorderRadius borderRadius; + final double borderWidth; + final Color colorFrom; + final Color colorTo; + final double progress; + final Color staticBorderColor; + @override void paint(Canvas canvas, Size size) { final rect = Rect.fromLTWH(0, 0, size.width, size.height); From 56d6785a8d93dde96e04f38f74ff6dfb91f56b16 Mon Sep 17 00:00:00 2001 From: SirDank <52797753+SirDank@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:54:56 +0530 Subject: [PATCH 2/2] Update border_beam.dart - fix alignment --- lib/fx_7_border_beam/border_beam.dart | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/fx_7_border_beam/border_beam.dart b/lib/fx_7_border_beam/border_beam.dart index 712af67..b737b21 100644 --- a/lib/fx_7_border_beam/border_beam.dart +++ b/lib/fx_7_border_beam/border_beam.dart @@ -51,24 +51,27 @@ class _BorderBeamState extends State @override Widget build(BuildContext context) { - return AnimatedBuilder( - animation: _animation, - builder: (context, child) { - return CustomPaint( - painter: BorderBeamPainter( - progress: _animation.value, - borderWidth: widget.borderWidth, - colorFrom: widget.colorFrom, - colorTo: widget.colorTo, - staticBorderColor: widget.staticBorderColor, - borderRadius: widget.borderRadius, - ), - child: Padding( - padding: widget.padding, - child: widget.child, - ), - ); - }, + return Padding( + padding: EdgeInsets.all(widget.borderWidth / 2), + child: AnimatedBuilder( + animation: _animation, + builder: (context, child) { + return CustomPaint( + painter: BorderBeamPainter( + progress: _animation.value, + borderWidth: widget.borderWidth, + colorFrom: widget.colorFrom, + colorTo: widget.colorTo, + staticBorderColor: widget.staticBorderColor, + borderRadius: widget.borderRadius, + ), + child: Padding( + padding: widget.padding, + child: widget.child, + ), + ); + }, + ), ); } }