From dcbed69e9606f40933bc517e8cd5131c886320e8 Mon Sep 17 00:00:00 2001 From: Hesham-Dev-LY <66942907+Hesham-Dev-LY@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:09:35 +0200 Subject: [PATCH 1/2] percentage fix --- lib/flutter_icon_rounded_progress_bar.dart | 2 +- lib/flutter_rounded_progress_bar.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/flutter_icon_rounded_progress_bar.dart b/lib/flutter_icon_rounded_progress_bar.dart index 61b7c68..1d0e3b4 100644 --- a/lib/flutter_icon_rounded_progress_bar.dart +++ b/lib/flutter_icon_rounded_progress_bar.dart @@ -130,7 +130,7 @@ class IconRoundedProgressBarState extends State { @override Widget build(BuildContext context) { width = MediaQuery.of(context).size.width; - widthProgress = width * widget.percent / 100; + widthProgress = width * (widget.percent / 100); return Container( margin: widget.margin, diff --git a/lib/flutter_rounded_progress_bar.dart b/lib/flutter_rounded_progress_bar.dart index b3c94de..92102f1 100644 --- a/lib/flutter_rounded_progress_bar.dart +++ b/lib/flutter_rounded_progress_bar.dart @@ -128,7 +128,7 @@ class RoundedProgressBarState extends State { Widget build(BuildContext context) { return LayoutBuilder(builder: (context, constraint) { width = constraint.maxWidth; - widthProgress = width * widget.percent / 100; + widthProgress = width * (widget.percent / 100); return Container( margin: widget.margin, decoration: BoxDecoration( From acd24e863f099a1ada0b75233bb317040f859767 Mon Sep 17 00:00:00 2001 From: Hesham-Dev-LY <66942907+Hesham-Dev-LY@users.noreply.github.com> Date: Sun, 11 Feb 2024 16:49:57 +0200 Subject: [PATCH 2/2] animation fix & enhancement --- lib/flutter_rounded_progress_bar.dart | 66 +++++++++++++++------------ 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/lib/flutter_rounded_progress_bar.dart b/lib/flutter_rounded_progress_bar.dart index 92102f1..b8ea060 100644 --- a/lib/flutter_rounded_progress_bar.dart +++ b/lib/flutter_rounded_progress_bar.dart @@ -4,6 +4,7 @@ import 'package:flutter_rounded_progress_bar/rounded_progress_bar_style.dart'; class RoundedProgressBar extends StatefulWidget { final double percent; final double height; + final int animationDelay; final RoundedProgressBarStyle? style; final RoundedProgressBarTheme? theme; final EdgeInsetsGeometry? margin; @@ -28,6 +29,7 @@ class RoundedProgressBar extends StatefulWidget { this.childLeft, this.childRight, this.milliseconds = 500, + this.animationDelay = 500, this.borderRadius, this.paddingChildLeft, this.paddingChildRight}) @@ -50,6 +52,7 @@ class RoundedProgressBarState extends State { BorderRadiusGeometry? borderRadius; EdgeInsetsGeometry? paddingChildLeft; EdgeInsetsGeometry? paddingChildRight; + bool _showProgress = false; @override void initState() { @@ -120,6 +123,11 @@ class RoundedProgressBarState extends State { } else { paddingChildRight = widget.paddingChildRight; } + Future.delayed(Duration(milliseconds: widget.animationDelay)).then((value) { + setState(() { + _showProgress = true; + }); + }); super.initState(); } @@ -128,7 +136,7 @@ class RoundedProgressBarState extends State { Widget build(BuildContext context) { return LayoutBuilder(builder: (context, constraint) { width = constraint.maxWidth; - widthProgress = width * (widget.percent / 100); + widthProgress = (width * (widget.percent / 100)); return Container( margin: widget.margin, decoration: BoxDecoration( @@ -143,33 +151,35 @@ class RoundedProgressBarState extends State { child: Row(mainAxisSize: MainAxisSize.max, children: [ Expanded( child: Stack(alignment: alignment, children: [ - AnimatedContainer( - duration: Duration(milliseconds: widget.milliseconds), - width: widthProgress! + style!.widthShadow, - decoration: BoxDecoration( - borderRadius: borderRadius, - color: style!.colorProgressDark)), - AnimatedContainer( - duration: Duration(milliseconds: widget.milliseconds), - width: widthProgress, - decoration: BoxDecoration( - borderRadius: borderRadius, - color: style!.colorProgress), - ), - Center(child: widget.childCenter), - Padding( - padding: paddingChildLeft!, - child: Align( - alignment: Alignment.centerLeft, - child: widget.childLeft), - ), - Padding( - padding: paddingChildRight!, - child: Align( - alignment: Alignment.centerRight, - child: widget.childRight), - ) - ])) + AnimatedContainer( + duration: Duration( + milliseconds: widget.milliseconds), + width: _showProgress ? widthProgress! + + style!.widthShadow : 0, + decoration: BoxDecoration( + borderRadius: borderRadius, + color: style!.colorProgressDark)), + AnimatedContainer( + duration: Duration(milliseconds: widget.milliseconds), + width: _showProgress ? widthProgress : 0, + decoration: BoxDecoration( + borderRadius: borderRadius, + color: style!.colorProgress), + ), + Center(child: widget.childCenter), + Padding( + padding: paddingChildLeft!, + child: Align( + alignment: Alignment.centerLeft, + child: widget.childLeft), + ), + Padding( + padding: paddingChildRight!, + child: Align( + alignment: Alignment.centerRight, + child: widget.childRight), + ) + ])) ])) ])); });