diff --git a/lib/components/badge/gf_badge.dart b/lib/components/badge/gf_badge.dart index 1c27b5b6..a30baabd 100644 --- a/lib/components/badge/gf_badge.dart +++ b/lib/components/badge/gf_badge.dart @@ -39,7 +39,7 @@ class GFBadge extends StatefulWidget { this.shape = GFBadgeShape.standard, this.color = GFColor.danger, this.textColor = GFColor.white, - this.size = GFSize.medium, + this.size = GFSize.small, this.border, this.text, this.child, diff --git a/lib/components/badge/gf_icon_badge.dart b/lib/components/badge/gf_icon_badge.dart index 96640b4a..ba24d4b5 100644 --- a/lib/components/badge/gf_icon_badge.dart +++ b/lib/components/badge/gf_icon_badge.dart @@ -27,8 +27,6 @@ class GFIconBadge extends StatefulWidget { } class _GFIconBadgeState extends State { - double size; - @override Widget build(BuildContext context) { return Container( @@ -37,8 +35,9 @@ class _GFIconBadgeState extends State { children: [ widget.child ?? Container(), new Positioned( - top: 2, - left: 22, +// top: 2, +// left: 22, + right: 0, child: widget.counterChild ?? Container(), ), ], diff --git a/lib/components/button/gf_icon_button.dart b/lib/components/button/gf_icon_button.dart index ef8b2fab..4f3049b0 100644 --- a/lib/components/button/gf_icon_button.dart +++ b/lib/components/button/gf_icon_button.dart @@ -226,7 +226,6 @@ class _GFIconButtonState extends State { this.width = 35.0; this.iconPixel = 18.0; } else if (widget.size == GFSize.large) { - print('her'); this.height = 40.0; this.width = 40.0; this.iconPixel = 18.0; diff --git a/lib/components/toast/gf_toast.dart b/lib/components/toast/gf_toast.dart index 45a7f13c..2a285a10 100644 --- a/lib/components/toast/gf_toast.dart +++ b/lib/components/toast/gf_toast.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:getflutter/colors/gf_color.dart'; import 'package:getflutter/components/toast/gf_floating_widget.dart'; +import 'package:getflutter/types/gf_toast_type.dart'; class GFToast extends StatefulWidget { ///Creates [GFToast] that can be used to display quick warning or error messages. @@ -14,6 +15,11 @@ class GFToast extends StatefulWidget { this.backgroundColor, this.text, this.width, + this.type = GFToastType.basic, + this.autoDismiss = true, + this.alignment, + this.animationDuration = const Duration(seconds: 2), + this.duration = const Duration(seconds: 2), this.textStyle = const TextStyle(color: Colors.white70), }) : super(key: key); @@ -32,86 +38,137 @@ class GFToast extends StatefulWidget { /// textStyle of type [textStyle] will be applicable to text only and not for the child final TextStyle textStyle; - /// width od type [double] used to control the width od the [GFToast] + /// width of type [double] used to control the width of the [GFToast] final double width; + ///type of [GFToastType] which takes the type ie, basic, rounded and fullWidth for the [GFToast] + final GFToastType type; + + ///type of [bool] which takes bool values ie, true or false to automatically hide the [GFToast] message + final bool autoDismiss; + + ///type of [Duration] which takes the duration of the fade in animation + final Duration animationDuration; + + ///type of [Duration] which takes the duration of the animation + final Duration duration; + + /// type of [Alignment] used to align the text inside the toast + final Alignment alignment; + @override _GFToastState createState() => _GFToastState(); } class _GFToastState extends State with TickerProviderStateMixin { - AnimationController controller, _controller; - Animation offset, offset1; - Animation animation; - Timer timer; - - bool slide = false; + AnimationController animationController, fadeanimationController; + Animation animation, fadeanimation; + bool hideToast = false; @override void initState() { - super.initState(); + animationController = AnimationController( + duration: const Duration(milliseconds: 2000), vsync: this); + animation = + CurvedAnimation(parent: animationController, curve: Curves.easeIn); - controller = AnimationController( - duration: const Duration(milliseconds: 300), vsync: this); - animation = CurvedAnimation(parent: controller, curve: Curves.easeIn); - _controller = - AnimationController(vsync: this, duration: Duration(milliseconds: 200)); - offset = Tween(begin: Offset.zero, end: Offset(0.0, 1.0)) - .animate(_controller); - controller.forward(); - _controller.forward(); + animationController.forward(); + + fadeanimationController = AnimationController( + vsync: this, + duration: widget.animationDuration, + )..addListener(() => setState(() {})); + fadeanimation = Tween( + begin: 0.0, + end: 1.0, + ).animate(fadeanimationController); + Timer(widget.duration, () { + fadeanimationController.forward(); + }); + + fadeanimation = Tween( + begin: 1.0, + end: 0.0, + ).animate(fadeanimationController); + + fadeanimation.addStatusListener((AnimationStatus state) { + if (fadeanimation.isCompleted && widget.autoDismiss) { + setState(() { + hideToast = true; + }); + } + }); + super.initState(); } @override void dispose() { - controller.dispose(); + animationController.dispose(); + fadeanimationController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { - return FadeTransition( - opacity: animation, - child: Column( - children: [ - Container( - width: widget.width != null ? widget.width : null, - constraints: BoxConstraints(minHeight: 50.0), -// width: 100, - margin: EdgeInsets.only(left: 10, right: 10), - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(3)), - color: widget.backgroundColor != null - ? GFColors.getGFColor(widget.backgroundColor) - : Color(0xff323232), - ), - child: Row( + return hideToast + ? Container() + : FadeTransition( + opacity: widget.autoDismiss ? fadeanimation : animation, + child: Column( children: [ - Flexible( - flex: 7, - fit: FlexFit.tight, - child: widget.text != null - ? Text(widget.text, style: widget.textStyle) - : (widget.child ?? Container()), - ), - SizedBox( - width: 10, + Container( + width: widget.type == GFToastType.fullWidth + ? MediaQuery.of(context).size.width + : widget.width, + constraints: BoxConstraints(minHeight: 50.0), + margin: widget.type == GFToastType.fullWidth + ? EdgeInsets.only(left: 0, right: 0) + : EdgeInsets.only(left: 10, right: 10), + padding: EdgeInsets.all(10), + decoration: BoxDecoration( + borderRadius: widget.type == GFToastType.basic + ? BorderRadius.circular(0.0) + : widget.type == GFToastType.rounded + ? BorderRadius.circular(10.0) + : BorderRadius.zero, + color: widget.backgroundColor != null + ? GFColors.getGFColor(widget.backgroundColor) + : Color(0xff323232), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.40), + blurRadius: 6.0) + ]), + child: Row( + children: [ + Flexible( + flex: 7, + fit: FlexFit.tight, + child: Align( + alignment: widget.alignment != null + ? widget.alignment + : Alignment.topLeft, + child: widget.text != null + ? Text(widget.text, style: widget.textStyle) + : (widget.child ?? Container()), + )), + SizedBox( + width: 10, + ), + widget.button != null + ? Flexible( + flex: 4, + fit: FlexFit.tight, + child: Align( + alignment: Alignment.topRight, + child: widget.button, + )) + : Container() + ], + ), ), - widget.button != null - ? Flexible( - flex: 4, - fit: FlexFit.tight, - child: Align( - alignment: Alignment.topRight, - child: widget.button, - )) - : Container() ], ), - ), - ], - ), - ); + ); } } diff --git a/lib/types/gf_toast_type.dart b/lib/types/gf_toast_type.dart new file mode 100644 index 00000000..4dcad3df --- /dev/null +++ b/lib/types/gf_toast_type.dart @@ -0,0 +1 @@ +enum GFToastType { basic, rounded, fullWidth }