Skip to content

Commit 2d49274

Browse files
Sandip KakadiyaSandip Kakadiya
authored andcommitted
Icon Button component reviewed
1 parent 2568877 commit 2d49274

10 files changed

Lines changed: 290 additions & 282 deletions

File tree

lib/components/avatar/gf_avatar.dart

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import 'package:flutter/widgets.dart';
22
import 'package:flutter/material.dart';
33
import 'package:ui_kit/shape/gf_avatar_shape.dart';
44
import 'package:ui_kit/size/gf_size.dart';
5+
import 'package:ui_kit/colors/gf_color.dart';
56

67
class GFAvatar extends StatelessWidget {
78
/// Typically a [Text] widget. If the [CircleAvatar] is to have an image, use [backgroundImage] instead.
89
final Widget child;
910

10-
/// The color with which to fill the circle.
11-
final Color backgroundColor;
11+
/// use [Color] or [GFColor]. The color with which to fill the circle.
12+
final dynamic backgroundColor;
1213

13-
/// The default text color for text in the circle.
14-
final Color foregroundColor;
14+
/// use [Color] or [GFColor]. The default text color for text in the circle.
15+
final dynamic foregroundColor;
1516

1617
/// The background image of the circle.
1718
final ImageProvider backgroundImage;
@@ -26,29 +27,19 @@ class GFAvatar extends StatelessWidget {
2627
final double maxRadius;
2728

2829
/// size of avatar like [double] or [GFSize] i.e, 1.2, small, medium, large etc.
29-
final GFSize size;
30+
final dynamic size;
3031

31-
/// shape of avatar [GFAvatarShape] i.e, standard, pills, square
32+
/// shape of avatar [GFAvatarShape] i.e, standard, circle, square
3233
final GFAvatarShape shape;
3334

3435
/// border radius to give extra radius for avatar square or standard shape
36+
/// Not applicable to circleshape
3537
final BorderRadius borderRadius;
3638

37-
// The default radius if nothing is specified.
38-
static const double _defaultRadius = 20.0;
39-
40-
// The default radius if avater size GFSize.small selected.
41-
static const double _smallRadius = 16.0;
42-
43-
// The default radius if avater size GFSize.large selected.
44-
static const double _largeRadius = 28.0;
45-
46-
// The default min if only the max is specified.
47-
static const double _defaultMinRadius = 0.0;
48-
49-
// The default max if only the min is specified.
50-
static const double _defaultMaxRadius = double.infinity;
39+
// /// The default max if only the min is specified.
40+
// static const double _defaultMaxRadius = double.infinity;
5141

42+
/// Create Avatar of all types i,e, square, circle, standard with different sizes.
5243
const GFAvatar(
5344
{Key key,
5445
this.child,
@@ -66,33 +57,17 @@ class GFAvatar extends StatelessWidget {
6657

6758
double get _minDiameter {
6859
if (radius == null && minRadius == null && maxRadius == null) {
69-
if (size == GFSize.medium) {
70-
return _defaultRadius * 2.0;
71-
} else if (size == GFSize.small) {
72-
return _smallRadius * 2.0;
73-
} else if (size == GFSize.large) {
74-
return _largeRadius * 2.0;
75-
} else {
76-
return _defaultRadius * 2.0;
77-
}
60+
return getGFSize(size);
7861
} else {
79-
return 2.0 * (radius ?? minRadius ?? _defaultMinRadius);
62+
return 2.0 * (radius ?? minRadius ?? 0);
8063
}
8164
}
8265

8366
double get _maxDiameter {
8467
if (radius == null && minRadius == null && maxRadius == null) {
85-
if (size == GFSize.medium) {
86-
return _defaultRadius * 2.0;
87-
} else if (size == GFSize.small) {
88-
return _smallRadius * 2.0;
89-
} else if (size == GFSize.large) {
90-
return _largeRadius * 2.0;
91-
} else {
92-
return _defaultRadius * 2.0;
93-
}
68+
return getGFSize(size);
9469
} else {
95-
return 2.0 * (radius ?? maxRadius ?? _defaultMaxRadius);
70+
return 2.0 * (radius ?? maxRadius ?? 0);
9671
}
9772
}
9873

@@ -110,6 +85,8 @@ class GFAvatar extends StatelessWidget {
11085

11186
@override
11287
Widget build(BuildContext context) {
88+
Color backgroundColor = getGFColor(this.backgroundColor);
89+
Color foregroundColor = getGFColor(this.foregroundColor);
11390
assert(debugCheckHasMediaQuery(context));
11491
final ThemeData theme = Theme.of(context);
11592
TextStyle textStyle =

lib/components/badge/gf_badge.dart

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ class GFBadge extends StatefulWidget {
1919
/// size of [double] or [GFSize] i.e, 1.2, small, medium, large etc.
2020
final GFSize size;
2121

22-
/// text of type [String] is alternative to child. text will get priority over child
22+
/// child of type [Widget] is alternative to child. text will get priority over child
2323
final Widget child;
2424

2525
/// text of type [String] is alternative to child. text will get priority over child
2626
final String text;
2727

28-
/// text style of counter text
28+
/// text style of counter text.
2929
final TextStyle textStyle;
3030

3131
/// Pass [GFColor] or [Color]
3232
final dynamic textColor;
3333

34-
/// Create badges of all types, check out [GFButtonBadge] for button badges and [GFIconBadge] for icon badges
34+
/// Create badges of all types, check out [GFButtonBadge] for button badges and [GFIconBadge] for icon type badges
3535
const GFBadge({
3636
Key key,
3737
this.textStyle,
3838
this.borderShape,
3939
this.shape = GFBadgeShape.standard,
40-
this.color = GFColor.secondary,
41-
this.textColor = GFColor.dark,
40+
this.color = GFColor.danger,
41+
this.textColor = GFColor.white,
4242
this.size = GFSize.medium,
4343
this.border,
4444
this.text,
@@ -64,7 +64,7 @@ class _GFBadgeState extends State<GFBadge> {
6464
void initState() {
6565
this.color = getGFColor(widget.color);
6666
this.textColor = getGFColor(widget.textColor);
67-
this.child = widget.child == null ? Text(widget.text) : widget.child;
67+
this.child = widget.text != null ? Text(widget.text ?? '') : widget.child;
6868
this.counterShape = widget.shape;
6969
this.size = widget.size;
7070
super.initState();
@@ -99,26 +99,28 @@ class _GFBadgeState extends State<GFBadge> {
9999
}
100100

101101
if (this.size == GFSize.small) {
102-
this.height = 18.0;
103-
this.width = 24.0;
104-
this.fontSize = 10.0;
102+
this.height = getGFSize(this.size) * 0.56;
103+
this.width = getGFSize(this.size) * 0.75;
104+
this.fontSize = getGFSize(this.size) * 0.31;
105105
} else if (this.size == GFSize.medium) {
106-
this.height = 20.0;
107-
this.width = 26.0;
106+
this.height = getGFSize(this.size) * 0.5;
107+
this.width = getGFSize(this.size) * 0.65;
108+
this.fontSize = getGFSize(this.size) * 0.3;
108109
this.fontSize = 12.0;
109110
} else if (this.size == GFSize.large) {
110-
this.height = 24.0;
111-
this.width = 30.0;
112-
this.fontSize = 12.0;
111+
this.height = getGFSize(this.size) * 0.428;
112+
this.width = getGFSize(this.size) * 0.535;
113+
this.fontSize = getGFSize(this.size) * 0.214;
113114
} else {
114-
this.height = 20.0;
115-
this.width = 26.0;
116-
this.fontSize = 12.0;
115+
this.height = getGFSize(this.size) * 0.56;
116+
this.width = getGFSize(this.size) * 0.75;
117+
this.fontSize = getGFSize(this.size) * 0.31;
117118
}
118119

119120
return Container(
120121
height: this.height,
121-
width: this.counterShape == GFBadgeShape.circle ? this.height : this.width,
122+
width:
123+
this.counterShape == GFBadgeShape.circle ? this.height : this.width,
122124
child: Material(
123125
textStyle: this.textColor != null
124126
? TextStyle(color: this.textColor, fontSize: this.fontSize)

lib/components/badge/gf_button_badge.dart

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import 'package:flutter/material.dart';
22
import 'package:ui_kit/shape/gf_badge_shape.dart';
3-
import 'package:ui_kit/shape/gf_badge_shape.dart';
4-
import 'package:ui_kit/shape/gf_badge_shape.dart';
5-
import 'package:ui_kit/shape/gf_badge_shape.dart';
63
import 'package:ui_kit/shape/gf_button_shape.dart';
74
import 'package:ui_kit/size/gf_size.dart';
85
import 'package:ui_kit/types/gf_type.dart';
@@ -29,7 +26,7 @@ class GFButtonBadge extends StatefulWidget {
2926
/// Badge type of [GFType] i.e, solid, outline, transparent
3027
final GFType type;
3128

32-
/// Badge type of [GFBadgeShape] i.e, standard, pills, square
29+
/// Badge type of [GFBadgeShape] i.e, standard, pills, square, circle
3330
final GFButtonShape shape;
3431

3532
/// Pass [GFColor] or [Color]
@@ -41,10 +38,11 @@ class GFButtonBadge extends StatefulWidget {
4138
/// size of [double] or [GFSize] i.e, 1.2, small, medium, large etc.
4239
final dynamic size;
4340

44-
/// text of type [String] is alternative to child. text will get priority over child
41+
/// text of type [String] is used to display text on the button.
4542
final String text;
4643

47-
/// text of type [String] is alternative to child. text will get priority over child
44+
/// child of type [Widget] is alternative to child. text will get priority over child.
45+
/// You can use [GFBadge] for compatibility.
4846
final Widget counterChild;
4947

5048
/// icon type of [GFPosition] i.e, start, end
@@ -88,7 +86,11 @@ class _GFButtonBadgeState extends State<GFButtonBadge> {
8886
@override
8987
void initState() {
9088
this.color = getGFColor(widget.color);
91-
this.textColor = widget.type == GFType.outline && widget.textColor == null ? this.color : widget.textColor == null ? getGFColor(GFColor.dark) : getGFColor(widget.textColor);
89+
this.textColor = (widget.type == GFType.outline && widget.textColor == null)
90+
? this.color
91+
: widget.textColor == null
92+
? getGFColor(GFColor.dark)
93+
: getGFColor(widget.textColor);
9294
this.onPressed = widget.onPressed;
9395
this.type = widget.type;
9496
this.shape = widget.shape;
@@ -104,19 +106,19 @@ class _GFButtonBadgeState extends State<GFButtonBadge> {
104106
child: Container(
105107
height: this.size,
106108
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
119-
),
109+
textStyle: widget.textStyle,
110+
borderSide: widget.borderSide,
111+
color: this.color,
112+
textColor: this.textColor,
113+
text: widget.text,
114+
onPressed: this.onPressed,
115+
type: this.type,
116+
shape: this.shape,
117+
position: this.position,
118+
size: this.size,
119+
borderShape: widget.borderShape,
120+
icon: widget.counterChild,
121+
),
120122
),
121123
);
122124
}

lib/components/badge/gf_icon_badge.dart

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import 'package:flutter/material.dart';
2-
import 'package:ui_kit/shape/gf_badge_shape.dart';
3-
import 'package:ui_kit/types/gf_type.dart';
4-
import 'package:ui_kit/position/gf_position.dart';
2+
import 'package:ui_kit/components/button/gf_icon_button.dart';
53

6-
class GFIconBadges extends StatefulWidget {
4+
class GFIconBadge extends StatefulWidget {
75
/// Called when the badge is tapped or otherwise activated.
86
final VoidCallback onPressed;
97

10-
/// text of type [String] is alternative to child. text will get priority over child
11-
final Widget child;
8+
/// child of type [GFIconButton] is used to show icon.
9+
/// Use [Icon] widget for compatibility.
10+
final GFIconButton child;
1211

13-
/// text of type [String] is alternative to child. text will get priority over child
12+
/// widget of type [Widget] is used to show counter to the top right corner of child.
13+
/// You can use [GFBadge] for compatibility.
1414
final Widget counterChild;
1515

1616
/// The internal padding for the badge's [child].
1717
final EdgeInsetsGeometry padding;
1818

1919
/// Create badges of all types, check out [GFBadge] for button badges and [GFIconBadge] for icon badges.
20-
const GFIconBadges({
20+
const GFIconBadge({
2121
Key key,
2222
@required this.onPressed,
2323
this.padding = const EdgeInsets.symmetric(horizontal: 8.0),
@@ -27,19 +27,10 @@ class GFIconBadges extends StatefulWidget {
2727
super(key: key);
2828

2929
@override
30-
_GFIconBadgesState createState() => _GFIconBadgesState();
30+
_GFIconBadgeState createState() => _GFIconBadgeState();
3131
}
3232

33-
class _GFIconBadgesState extends State<GFIconBadges> {
34-
Color badgeColor, counterColor;
35-
Color textColor;
36-
Widget child;
37-
Widget icon;
38-
Function onPressed;
39-
GFType type;
40-
GFBadgeShape shape;
41-
GFPosition position;
42-
33+
class _GFIconBadgeState extends State<GFIconBadge> {
4334
@override
4435
void initState() {
4536
super.initState();
@@ -50,13 +41,14 @@ class _GFIconBadgesState extends State<GFIconBadges> {
5041
return Container(
5142
height: 60.0,
5243
width: 60.0,
44+
padding: widget.padding,
5345
child: Stack(
5446
children: <Widget>[
55-
widget.child,
47+
widget.child ?? Container(),
5648
new Positioned(
5749
top: 2,
5850
left: 22,
59-
child: widget.counterChild,
51+
child: widget.counterChild ?? Container(),
6052
),
6153
],
6254
),

0 commit comments

Comments
 (0)