@@ -4,37 +4,78 @@ import 'package:flutter_svg/svg.dart';
44
55/// 头像的类型,包含有皇冠的和没有皇冠的
66/// normal | crownLarge | crownSmall
7- enum AvatarType {
8- normal,
9- crownLarge,
10- crownSmall
11- }
7+ enum AvatarType { normal, crownLarge, crownSmall }
8+
129class CrownAvatar extends StatefulWidget {
1310 final AvatarType crownAvatarType;
1411 final int color;
12+ final String avatarUrl;
1513
1614 CrownAvatar (
17- {@required this .crownAvatarType, this .color = AppColors .colorRed}) {
18- switch (this .crownAvatarType) {
19- case AvatarType .normal:
20- // this.imageSize = 4;
21- break ;
22-
23- default :
24- }
25- }
15+ {@required this .crownAvatarType,
16+ @required this .avatarUrl,
17+ this .color = AppColors .colorRed});
2618
2719 @override
2820 _CrownAvatarState createState () => _CrownAvatarState ();
2921}
3022
3123class _CrownAvatarState extends State <CrownAvatar > {
32- int imageSize = 75 ;
24+ double imageSize = 75.0 ;
25+ // 皇冠的宽高
26+ double crownWidth = 37.0 ;
27+ double crownHeight = 30.0 ;
28+ // 距离顶部的高度
29+ double crowTop = - 18.0 ;
30+ // 圆圈的大小
31+ double circleSize = 18.0 ;
32+ // 圆圈里面的字体大小
33+ double circleFontSize = 14.0 ;
34+ double crownTextSize = 16.0 ;
3335
3436 @override
3537 Widget build (BuildContext context) {
38+ // 判断头像的类型给出对应的尺寸
39+ if (widget.crownAvatarType == AvatarType .crownLarge) {
40+ this .imageSize = 100.0 ;
41+ this .crownWidth = 67.0 ;
42+ this .crownHeight = 53.0 ;
43+ this .crowTop = - 36.0 ;
44+ this .circleSize = 24.0 ;
45+ this .circleFontSize = 16.0 ;
46+ this .crownTextSize = 18.0 ;
47+ }
48+ // 返回有关注按钮的头像组件
49+ if (widget.crownAvatarType == AvatarType .normal) {
50+ return Container (
51+ margin: EdgeInsets .only (right: 24.0 ),
52+ child: Column (
53+ children: < Widget > [
54+ ClipRRect (
55+ borderRadius: BorderRadius .circular (40.0 ),
56+ child: Image .network (
57+ widget.avatarUrl,
58+ width: 60.0 ,
59+ height: 60.0 ,
60+ fit: BoxFit .cover,
61+ ),
62+ ),
63+ Text (
64+ "阿明" ,
65+ style:
66+ TextStyle (color: Color (AppColors .fontColor), fontSize: 16.0 ),
67+ ),
68+ MaterialButton (
69+ onPressed: () {},
70+ child: Text ("关注" ),
71+ color: Color (AppColors .lightGray),
72+ )
73+ ],
74+ ),
75+ );
76+ }
3677 return Container (
37- padding: EdgeInsets .only (top: 24 .0 ),
78+ padding: EdgeInsets .only (top: 60.0 , bottom : 37 .0 ),
3879 child: Column (
3980 children: < Widget > [
4081 Stack (
@@ -43,48 +84,50 @@ class _CrownAvatarState extends State<CrownAvatar> {
4384 ClipRRect (
4485 borderRadius: BorderRadius .circular (100.0 ),
4586 child: Image .network (
46- "http://admin.soscoon.com/uploadImages/0136afa3b04e2d754feaed525fa02f474dd08aa0.jpg" ,
47- width: 75.0 ,
48- height: 75.0 ,
87+ widget.avatarUrl ,
88+ width: imageSize ,
89+ height: imageSize ,
4990 fit: BoxFit .cover,
5091 ),
5192 ),
5293 Positioned (
53- width: 75.0 ,
94+ width: imageSize ,
5495 child: SvgPicture .asset (
5596 'assets/icon/icon_crown.svg' ,
56- width: 37.0 ,
57- height: 30.0 ,
97+ width: crownWidth ,
98+ height: crownHeight ,
5899 color: Color (widget.color),
59100 ),
60- top: - 18.0 ,
101+ top: crowTop ,
61102 left: 0 )
62103 ],
63104 ),
64105 Row (
65106 mainAxisAlignment: MainAxisAlignment .center,
66107 children: < Widget > [
67108 Container (
68- width: 18.0 ,
69- height: 18.0 ,
109+ width: circleSize ,
110+ height: circleSize ,
70111 child: Align (
71112 alignment: Alignment .center,
72113 child: Text (
73114 "2" ,
74115 style: TextStyle (
75- color: Color (AppColors .fontColor), fontSize: 14.0 ),
116+ color: Color (AppColors .fontColor),
117+ fontSize: circleFontSize),
76118 ),
77119 ),
78120 decoration: BoxDecoration (
79121 color: Color (widget.color),
80- borderRadius: BorderRadius .circular (20 .0 )),
122+ borderRadius: BorderRadius .circular (40 .0 )),
81123 ),
82124 SizedBox (
83125 width: 4.0 ,
84126 ),
85127 Text (
86128 "大中华区" ,
87- style: TextStyle (color: Color (widget.color), fontSize: 16.0 ),
129+ style: TextStyle (
130+ color: Color (widget.color), fontSize: crownTextSize),
88131 )
89132 ],
90133 ),
@@ -95,7 +138,8 @@ class _CrownAvatarState extends State<CrownAvatar> {
95138 child: Text (
96139 "46" ,
97140 style: TextStyle (
98- color: Color (AppColors .fontColorGray), fontSize: 16.0 ),
141+ color: Color (AppColors .fontColorGray),
142+ fontSize: crownTextSize),
99143 ),
100144 ),
101145 SizedBox (
@@ -104,7 +148,8 @@ class _CrownAvatarState extends State<CrownAvatar> {
104148 Text (
105149 "关注者" ,
106150 style: TextStyle (
107- color: Color (AppColors .fontColorGray), fontSize: 16.0 ),
151+ color: Color (AppColors .fontColorGray),
152+ fontSize: crownTextSize),
108153 )
109154 ],
110155 ),
0 commit comments