11import 'package:flutter/material.dart' ;
22import 'package:ui_kit/shape/gf_shape.dart' ;
33import 'package:ui_kit/size/gf_size.dart' ;
4- import 'package:ui_kit/types/gf_type.dart' ;
5- import 'package:ui_kit/position/gf_position.dart' ;
64import 'package:ui_kit/colors/color.dart' ;
7- import 'package:ui_kit/components/button/gf_button.dart' ;
85
9- class GFBadges extends StatefulWidget {
6+ class GFBadge extends StatefulWidget {
107
11- /// Called when the badge is tapped or otherwise activated .
12- final VoidCallback onPressed ;
8+ /// The border side for the button's [Material] .
9+ final BorderSide border ;
1310
14- /// Defines the default text style, with [Material.textStyle] , for the button's [child] .
15- final TextStyle textStyle;
16-
17- /// The border side for the badge's [Material] .
18- final BorderSide borderSide;
19-
20- /// The internal padding for the badge's [child] .
21- final EdgeInsetsGeometry padding;
22-
23- /// The shape of the badge's [Material] .
11+ /// Typically the counter button's shape.
2412 final ShapeBorder borderShape;
2513
26- /// Badge type of [GFType] i.e, solid, outline, transparent
27- final GFType type;
28-
29- /// Badge type of [GFShape] i.e, standard, pills, square
14+ /// Counter type of [GFShape] i.e, standard, pills, square,
3015 final GFShape shape;
3116
3217 /// Pass [GFColor] or [Color]
3318 final dynamic color;
3419
35- /// Pass [GFColor] or [Color]
36- final dynamic textColor;
37-
3820 /// size of [double] or [GFSize] i.e, 1.2, small, medium, large etc.
39- final dynamic size;
21+ final GFSize size;
4022
4123 /// text of type [String] is alternative to child. text will get priority over child
42- final String text ;
24+ final Widget child ;
4325
4426 /// text of type [String] is alternative to child. text will get priority over child
45- final Widget counterChild;
27+ final String text;
28+
29+ /// text style of counter text
30+ final TextStyle textStyle;
4631
47- /// icon type of [GFPosition] i.e, start, end
48- final GFPosition position ;
32+ /// Pass [GFColor] or [Color]
33+ final dynamic textColor ;
4934
50- /// Create badges of all types. check out gfIconBadges for icon badges
5135
52- const GFBadges ({
36+ /// Create counter of all types, check out [GFBadge] for button badges and [GFIconBadge] for icon badges
37+
38+ const GFBadge ({
5339 Key key,
54- @required this .onPressed,
5540 this .textStyle,
56- this .padding = const EdgeInsets .symmetric (horizontal: 8.0 ),
5741 this .borderShape,
58- this .type = GFType .solid,
5942 this .shape = GFShape .standard,
60- this .color = GFColor .primary ,
43+ this .color = GFColor .secondary ,
6144 this .textColor = GFColor .dark,
62- this .position = GFPosition .end,
6345 this .size = GFSize .medium,
64- this .borderSide ,
65- @required this .text,
66- @required this .counterChild ,
46+ this .border ,
47+ this .text,
48+ @required this .child ,
6749 }) :
68- assert (shape != null , 'Badge shape can not be null' ,),
69- assert (padding != null ),
50+ assert (shape != null , 'Counter shape can not be null' ,),
7051 super (key: key);
7152
7253 @override
73- _GFBadgesState createState () => _GFBadgesState ();
54+ _GFBadgeState createState () => _GFBadgeState ();
7455}
7556
76- class _GFBadgesState extends State <GFBadges > {
57+ class _GFBadgeState extends State <GFBadge > {
7758 Color color;
7859 Color textColor;
7960 Widget child;
80- Widget icon;
81- Function onPressed;
82- GFType type;
83- GFShape shape;
84- double size;
85- GFPosition position;
61+ GFShape counterShape;
62+ GFSize size;
63+ double height;
64+ double width;
65+ double fontSize;
8666
8767 @override
8868 void initState () {
8969 this .color = getGFColor (widget.color);
9070 this .textColor = getGFColor (widget.textColor);
91- this .onPressed = widget.onPressed;
92- this .type = widget.type;
93- this .shape = widget.shape;
94- this .size = getGFSize (widget.size);
95- this .position = widget.position;
71+ this .child = widget.child == null ? Text (widget.text) : widget.child;
72+ this .counterShape = widget.shape;
73+ this .size = widget.size;
9674 super .initState ();
9775 }
9876
9977 @override
10078 Widget build (BuildContext context) {
10179
102- return ConstrainedBox (
103- constraints: BoxConstraints (minHeight: 26.0 , minWidth: 98.0 ),
104- child: Container (
105- height: this .size,
106- child: GFButton (
107- textStyle: widget.textStyle,
108- borderSide: widget.borderSide,
109- color: this .color,
110- textColor: this .textColor,
111- text: widget.text,
112- onPressed: this .onPressed,
113- type: this .type,
114- shape: this .shape,
115- position: this .position,
116- size: this .size,
117- borderShape: widget.borderShape,
118- icon: widget.counterChild
80+ final Color themeColor = Theme .of (context).colorScheme.onSurface.withOpacity (0.12 );
81+ final BorderSide shapeBorder = widget.border != null ? widget.border : BorderSide (color: this .color, width: 0.0 ,);
82+
83+ ShapeBorder shape;
84+
85+ if (this .counterShape == GFShape .pills){
86+ shape = RoundedRectangleBorder (borderRadius: BorderRadius .circular (50.0 ), side: shapeBorder);
87+ }else if (this .counterShape == GFShape .square){
88+ shape = RoundedRectangleBorder (borderRadius: BorderRadius .circular (0.0 ), side: shapeBorder);
89+ }else if (this .counterShape == GFShape .standard){
90+ shape = RoundedRectangleBorder (borderRadius: BorderRadius .circular (5.0 ), side: shapeBorder);
91+ }else if (this .counterShape == GFShape .circle) {
92+ shape = RoundedRectangleBorder (borderRadius: BorderRadius .circular (100.0 ), side: shapeBorder);
93+ }
94+
95+ if (this .size == GFSize .small){
96+ this .height = 18.0 ; this .width = 24.0 ; this .fontSize = 10.0 ;
97+ }else if (this .size == GFSize .medium){
98+ this .height = 20.0 ; this .width = 26.0 ; this .fontSize = 12.0 ;
99+ }else if (this .size == GFSize .large){
100+ this .height = 24.0 ; this .width = 30.0 ; this .fontSize = 12.0 ;
101+ }
102+
103+
104+ return Container (
105+ height: this .height,
106+ width: this .counterShape == GFShape .circle ? this .height : this .width,
107+ child: Material (
108+ textStyle: this .textColor != null ? TextStyle (color: this .textColor, fontSize: this .fontSize): widget.textStyle,
109+ shape: widget.borderShape == null ? shape : widget.borderShape,
110+ color: this .color,
111+ type: MaterialType .button,
112+ child: Container (
113+ child: Center (
114+ widthFactor: 1.0 ,
115+ heightFactor: 1.0 ,
116+ child: this .child,
117+ ),
119118 ),
120119 ),
121120 );
122121 }
123- }
122+ }
0 commit comments