Skip to content

Commit 8ce25e8

Browse files
Merge pull request #6 from Sandipkakadiya/review
reviewed work done
2 parents 022cd28 + caac79b commit 8ce25e8

File tree

11 files changed

+413
-337
lines changed

11 files changed

+413
-337
lines changed

lib/components/avatar/gf_avatar.dart

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,6 @@ import 'package:ui_kit/shape/gf_shape.dart';
44
import 'package:ui_kit/size/gf_size.dart';
55

66
class GFAvatar extends StatelessWidget {
7-
8-
const GFAvatar({
9-
Key key,
10-
this.child,
11-
this.backgroundColor,
12-
this.backgroundImage,
13-
this.foregroundColor,
14-
this.radius,
15-
this.minRadius,
16-
this.maxRadius,
17-
this.borderRadius,
18-
this.shape = GFShape.pills,
19-
this.size = GFSize.medium
20-
}) : assert(radius == null || (minRadius == null && maxRadius == null)),
21-
super(key: key);
22-
237
/// Typically a [Text] widget. If the [CircleAvatar] is to have an image, use [backgroundImage] instead.
248
final Widget child;
259

@@ -65,30 +49,51 @@ class GFAvatar extends StatelessWidget {
6549
// The default max if only the min is specified.
6650
static const double _defaultMaxRadius = double.infinity;
6751

52+
const GFAvatar(
53+
{Key key,
54+
this.child,
55+
this.backgroundColor,
56+
this.backgroundImage,
57+
this.foregroundColor,
58+
this.radius,
59+
this.minRadius,
60+
this.maxRadius,
61+
this.borderRadius,
62+
this.shape = GFShape.pills,
63+
this.size = GFSize.medium})
64+
: assert(radius == null || (minRadius == null && maxRadius == null)),
65+
super(key: key);
66+
6867
double get _minDiameter {
69-
if (radius == null && minRadius == null && maxRadius == null && size == GFSize.medium ) {
70-
return _defaultRadius * 2.0;
71-
}
72-
if (radius == null && minRadius == null && maxRadius == null && size == GFSize.small) {
73-
return _smallRadius * 2.0;
74-
}
75-
if (radius == null && minRadius == null && maxRadius == null && size == GFSize.large) {
76-
return _largeRadius * 2.0;
68+
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+
}
78+
} else {
79+
return 2.0 * (radius ?? minRadius ?? _defaultMinRadius);
7780
}
78-
return 2.0 * (radius ?? minRadius ?? _defaultMinRadius);
7981
}
8082

8183
double get _maxDiameter {
82-
if (radius == null && minRadius == null && maxRadius == null && size == GFSize.medium ) {
83-
return _defaultRadius * 2.0;
84-
}
85-
if (radius == null && minRadius == null && maxRadius == null && size == GFSize.small) {
86-
return _smallRadius * 2.0;
87-
}
88-
if (radius == null && minRadius == null && maxRadius == null && size == GFSize.large) {
89-
return _largeRadius * 2.0;
84+
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+
}
94+
} else {
95+
return 2.0 * (radius ?? maxRadius ?? _defaultMaxRadius);
9096
}
91-
return 2.0 * (radius ?? maxRadius ?? _defaultMaxRadius);
9297
}
9398

9499
BoxShape get _avatarShape {
@@ -98,15 +103,17 @@ class GFAvatar extends StatelessWidget {
98103
return BoxShape.rectangle;
99104
} else if (shape == GFShape.standard) {
100105
return BoxShape.rectangle;
106+
} else {
107+
return BoxShape.rectangle;
101108
}
102109
}
103110

104-
105111
@override
106112
Widget build(BuildContext context) {
107113
assert(debugCheckHasMediaQuery(context));
108114
final ThemeData theme = Theme.of(context);
109-
TextStyle textStyle = theme.primaryTextTheme.subhead.copyWith(color: foregroundColor);
115+
TextStyle textStyle =
116+
theme.primaryTextTheme.subhead.copyWith(color: foregroundColor);
110117
Color effectiveBackgroundColor = backgroundColor;
111118

112119
if (effectiveBackgroundColor == null) {
@@ -144,22 +151,24 @@ class GFAvatar extends StatelessWidget {
144151
? DecorationImage(image: backgroundImage, fit: BoxFit.cover)
145152
: null,
146153
shape: _avatarShape,
147-
borderRadius: shape == GFShape.standard && borderRadius == null ? BorderRadius.circular(10.0) : borderRadius,
154+
borderRadius: shape == GFShape.standard && borderRadius == null
155+
? BorderRadius.circular(10.0)
156+
: borderRadius,
148157
),
149158
child: child == null
150159
? null
151160
: Center(
152-
child: MediaQuery(
153-
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
154-
child: IconTheme(
155-
data: theme.iconTheme.copyWith(color: textStyle.color),
156-
child: DefaultTextStyle(
157-
style: textStyle,
158-
child: child,
161+
child: MediaQuery(
162+
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
163+
child: IconTheme(
164+
data: theme.iconTheme.copyWith(color: textStyle.color),
165+
child: DefaultTextStyle(
166+
style: textStyle,
167+
child: child,
168+
),
169+
),
170+
),
159171
),
160-
),
161-
),
162-
),
163172
);
164173
}
165174
}

lib/components/badge/gf_badge.dart

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:ui_kit/shape/gf_shape.dart';
33
import 'package:ui_kit/size/gf_size.dart';
4-
import 'package:ui_kit/colors/color.dart';
4+
import 'package:ui_kit/colors/gf_color.dart';
55

66
class GFBadge extends StatefulWidget {
7-
87
/// The border side for the button's [Material].
98
final BorderSide border;
109

@@ -32,9 +31,7 @@ class GFBadge extends StatefulWidget {
3231
/// Pass [GFColor] or [Color]
3332
final dynamic textColor;
3433

35-
36-
/// Create counter of all types, check out [GFBadge] for button badges and [GFIconBadge] for icon badges
37-
34+
/// Create badges of all types, check out [GFButtonBadge] for button badges and [GFIconBadge] for icon badges
3835
const GFBadge({
3936
Key key,
4037
this.textStyle,
@@ -46,8 +43,7 @@ class GFBadge extends StatefulWidget {
4643
this.border,
4744
this.text,
4845
@required this.child,
49-
}) :
50-
assert(shape != null, 'Counter shape can not be null',),
46+
}) : assert(shape != null, 'Counter shape can not be null'),
5147
super(key: key);
5248

5349
@override
@@ -76,36 +72,57 @@ class _GFBadgeState extends State<GFBadge> {
7672

7773
@override
7874
Widget build(BuildContext context) {
79-
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,);
75+
final BorderSide shapeBorder = widget.border != null
76+
? widget.border
77+
: BorderSide(
78+
color: this.color,
79+
width: 0.0,
80+
);
8281

8382
ShapeBorder shape;
8483

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);
84+
if (this.counterShape == GFShape.pills) {
85+
shape = RoundedRectangleBorder(
86+
borderRadius: BorderRadius.circular(50.0), side: shapeBorder);
87+
} else if (this.counterShape == GFShape.square) {
88+
shape = RoundedRectangleBorder(
89+
borderRadius: BorderRadius.circular(0.0), side: shapeBorder);
90+
} else if (this.counterShape == GFShape.standard) {
91+
shape = RoundedRectangleBorder(
92+
borderRadius: BorderRadius.circular(5.0), side: shapeBorder);
93+
} else if (this.counterShape == GFShape.circle) {
94+
shape = RoundedRectangleBorder(
95+
borderRadius: BorderRadius.circular(100.0), side: shapeBorder);
96+
} else {
97+
shape = RoundedRectangleBorder(
98+
borderRadius: BorderRadius.circular(5.0), side: shapeBorder);
9399
}
94100

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+
if (this.size == GFSize.small) {
102+
this.height = 18.0;
103+
this.width = 24.0;
104+
this.fontSize = 10.0;
105+
} else if (this.size == GFSize.medium) {
106+
this.height = 20.0;
107+
this.width = 26.0;
108+
this.fontSize = 12.0;
109+
} else if (this.size == GFSize.large) {
110+
this.height = 24.0;
111+
this.width = 30.0;
112+
this.fontSize = 12.0;
113+
} else {
114+
this.height = 20.0;
115+
this.width = 26.0;
116+
this.fontSize = 12.0;
101117
}
102118

103-
104119
return Container(
105120
height: this.height,
106121
width: this.counterShape == GFShape.circle ? this.height : this.width,
107122
child: Material(
108-
textStyle: this.textColor != null ? TextStyle(color: this.textColor, fontSize: this.fontSize): widget.textStyle,
123+
textStyle: this.textColor != null
124+
? TextStyle(color: this.textColor, fontSize: this.fontSize)
125+
: widget.textStyle,
109126
shape: widget.borderShape == null ? shape : widget.borderShape,
110127
color: this.color,
111128
type: MaterialType.button,

lib/components/badge/gf_button_badge.dart

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import 'package:ui_kit/shape/gf_shape.dart';
33
import 'package:ui_kit/size/gf_size.dart';
44
import 'package:ui_kit/types/gf_type.dart';
55
import 'package:ui_kit/position/gf_position.dart';
6-
import 'package:ui_kit/colors/color.dart';
6+
import 'package:ui_kit/colors/gf_color.dart';
77
import 'package:ui_kit/components/button/gf_button.dart';
88

99
class GFButtonBadge extends StatefulWidget {
10-
1110
/// Called when the badge is tapped or otherwise activated.
1211
final VoidCallback onPressed;
1312

@@ -47,8 +46,7 @@ class GFButtonBadge extends StatefulWidget {
4746
/// icon type of [GFPosition] i.e, start, end
4847
final GFPosition position;
4948

50-
/// Create badges of all types. check out [GFIconBadge] for icon badges
51-
49+
/// Create badges of all types. check out [GFIconBadge] for icon badges and [GFBadge] for default badges.
5250
const GFButtonBadge({
5351
Key key,
5452
@required this.onPressed,
@@ -64,8 +62,7 @@ class GFButtonBadge extends StatefulWidget {
6462
this.borderSide,
6563
@required this.text,
6664
@required this.counterChild,
67-
}) :
68-
assert(shape != null, 'Badge shape can not be null',),
65+
}) : assert(shape != null, 'Badge shape can not be null'),
6966
assert(padding != null),
7067
super(key: key);
7168

@@ -98,26 +95,24 @@ class _GFButtonBadgeState extends State<GFButtonBadge> {
9895

9996
@override
10097
Widget build(BuildContext context) {
101-
10298
return ConstrainedBox(
10399
constraints: BoxConstraints(minHeight: 26.0, minWidth: 98.0),
104100
child: Container(
105101
height: this.size,
106102
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-
),
103+
textStyle: widget.textStyle,
104+
borderSide: widget.borderSide,
105+
color: this.color,
106+
textColor: this.textColor,
107+
text: widget.text,
108+
onPressed: this.onPressed,
109+
type: this.type,
110+
shape: this.shape,
111+
position: this.position,
112+
size: this.size,
113+
borderShape: widget.borderShape,
114+
icon: widget.counterChild),
120115
),
121116
);
122117
}
123-
}
118+
}

lib/components/badge/gf_icon_badge.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:ui_kit/types/gf_type.dart';
44
import 'package:ui_kit/position/gf_position.dart';
55

66
class GFIconBadges extends StatefulWidget {
7-
87
/// Called when the badge is tapped or otherwise activated.
98
final VoidCallback onPressed;
109

@@ -17,17 +16,14 @@ class GFIconBadges extends StatefulWidget {
1716
/// The internal padding for the badge's [child].
1817
final EdgeInsetsGeometry padding;
1918

20-
21-
/// Create badges of all types, check out [GFBadge] for button badges
22-
19+
/// Create badges of all types, check out [GFBadge] for button badges and [GFIconBadge] for icon badges.
2320
const GFIconBadges({
2421
Key key,
2522
@required this.onPressed,
2623
this.padding = const EdgeInsets.symmetric(horizontal: 8.0),
2724
@required this.child,
2825
@required this.counterChild,
29-
}) :
30-
assert(padding != null),
26+
}) : assert(padding != null),
3127
super(key: key);
3228

3329
@override
@@ -51,9 +47,9 @@ class _GFIconBadgesState extends State<GFIconBadges> {
5147

5248
@override
5349
Widget build(BuildContext context) {
54-
5550
return Container(
56-
height: 60.0, width: 60.0,
51+
height: 60.0,
52+
width: 60.0,
5753
child: Stack(
5854
children: <Widget>[
5955
widget.child,
@@ -66,4 +62,4 @@ class _GFIconBadgesState extends State<GFIconBadges> {
6662
),
6763
);
6864
}
69-
}
65+
}

0 commit comments

Comments
 (0)