2020-01-01 18:10:13 +00:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-01-18 12:22:22 +00:00
|
|
|
import 'package:fluffychat/utils/string_color.dart';
|
2020-01-01 18:10:13 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'matrix.dart';
|
|
|
|
|
|
|
|
class Avatar extends StatelessWidget {
|
|
|
|
final MxContent mxContent;
|
2020-01-18 12:22:22 +00:00
|
|
|
final String name;
|
2020-01-01 18:10:13 +00:00
|
|
|
final double size;
|
2020-01-17 10:08:12 +00:00
|
|
|
final Function onTap;
|
2020-03-13 20:42:05 +00:00
|
|
|
static const double defaultSize = 44;
|
2020-01-01 18:10:13 +00:00
|
|
|
|
2020-03-13 20:42:05 +00:00
|
|
|
const Avatar(
|
|
|
|
this.mxContent,
|
|
|
|
this.name, {
|
|
|
|
this.size = defaultSize,
|
|
|
|
this.onTap,
|
|
|
|
Key key,
|
|
|
|
}) : super(key: key);
|
2020-01-01 18:10:13 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final String src = mxContent.getThumbnail(
|
|
|
|
Matrix.of(context).client,
|
|
|
|
width: size * MediaQuery.of(context).devicePixelRatio,
|
|
|
|
height: size * MediaQuery.of(context).devicePixelRatio,
|
|
|
|
method: ThumbnailMethod.scale,
|
|
|
|
);
|
2020-01-18 12:22:22 +00:00
|
|
|
String fallbackLetters = "@";
|
|
|
|
if ((name?.length ?? 0) >= 2) {
|
|
|
|
fallbackLetters = name.substring(0, 2);
|
|
|
|
} else if ((name?.length ?? 0) == 1) {
|
|
|
|
fallbackLetters = name;
|
|
|
|
}
|
2020-01-17 10:08:12 +00:00
|
|
|
return InkWell(
|
|
|
|
onTap: onTap,
|
|
|
|
child: CircleAvatar(
|
|
|
|
radius: size / 2,
|
|
|
|
backgroundImage: mxContent.mxc?.isNotEmpty ?? false
|
|
|
|
? kIsWeb
|
|
|
|
? NetworkImage(
|
|
|
|
src,
|
|
|
|
)
|
|
|
|
: CachedNetworkImageProvider(
|
|
|
|
src,
|
|
|
|
)
|
|
|
|
: null,
|
2020-01-19 14:07:42 +00:00
|
|
|
backgroundColor: mxContent.mxc.isEmpty
|
|
|
|
? name?.color ?? Theme.of(context).secondaryHeaderColor
|
|
|
|
: Theme.of(context).secondaryHeaderColor,
|
2020-01-17 10:08:12 +00:00
|
|
|
child: mxContent.mxc.isEmpty
|
2020-01-18 12:22:22 +00:00
|
|
|
? Text(fallbackLetters, style: TextStyle(color: Colors.white))
|
2020-01-17 10:08:12 +00:00
|
|
|
: null,
|
|
|
|
),
|
2020-01-01 18:10:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|