/
avatar.dart
51 lines (45 loc) · 1.17 KB
/
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
import 'dart:math';
import 'package:flutter/material.dart';
class FLAvatar extends StatelessWidget {
FLAvatar(
{Key key,
this.image,
this.color,
this.text,
this.textStyle,
this.width,
this.height,
this.radius,
this.onTap})
: super(key: key);
final Image image;
/// Only use color for image == null.
final Color color;
final String text;
final TextStyle textStyle;
final double width;
final double height;
/// Default is width / 2, if width is null, radius = 1.
final double radius;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final double rad = radius ?? (width != null ? max(width / 2, 1) : 1);
final bool isImageAva = image != null;
final Widget content = isImageAva ? image : Text(text, style: textStyle);
return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(rad)),
child: GestureDetector(
onTap: onTap,
child: Container(
color: isImageAva ? null : color,
width: width,
height: height,
child: Center(
child: content,
),
),
),
);
}
}