@@ -4,22 +4,6 @@ import 'package:ui_kit/shape/gf_shape.dart';
44import 'package:ui_kit/size/gf_size.dart' ;
55
66class 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}
0 commit comments