-
Notifications
You must be signed in to change notification settings - Fork 10
/
clickable_avatar.dart
68 lines (66 loc) · 2.08 KB
/
clickable_avatar.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import 'package:byr_mobile_app/customizations/theme_controller.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class ClickableAvatar extends StatelessWidget {
final double radius;
final bool emptyUser;
final String imageLink;
final onTap;
final isWhisper;
const ClickableAvatar({
Key key,
@required this.radius,
@required this.emptyUser,
this.imageLink,
this.onTap,
this.isWhisper = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Widget placeHolder = Container(
alignment: Alignment.center,
child: Icon(
FontAwesomeIcons.solidUserCircle,
color: Colors.grey.withOpacity(0.5),
size: radius * 2,
),
decoration: BoxDecoration(color: Colors.transparent, shape: BoxShape.circle),
);
Widget avatar = isWhisper
? Container(
width: radius * 2,
height: radius * 2,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.transparent,
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage("resources/user/whisper_face.jpg"),
),
),
)
: emptyUser
? placeHolder
: CachedNetworkImage(
alignment: Alignment.center,
color: E().userPageSecondaryBackgroundColor,
imageUrl: imageLink,
imageBuilder: (context, imageProvider) => CircleAvatar(
backgroundColor: E().userPageSecondaryBackgroundColor,
radius: radius,
backgroundImage: imageProvider,
),
placeholder: (context, url) => placeHolder,
errorWidget: (context, url, error) => placeHolder,
);
if (onTap != null) {
return GestureDetector(
child: avatar,
onTap: this.onTap,
);
} else {
return avatar;
}
}
}