2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-11-02 14:44:26 +01:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2020-01-13 14:07:28 +01:00
|
|
|
import 'package:git_touch/widgets/link.dart';
|
2019-11-02 14:44:26 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2019-12-22 04:11:13 +01:00
|
|
|
class AvatarSize {
|
|
|
|
static const double extraSmall = 20;
|
|
|
|
static const double small = 24;
|
|
|
|
static const double medium = 36;
|
|
|
|
static const double large = 48;
|
2020-01-12 07:49:46 +01:00
|
|
|
static const double extraLarge = 64;
|
2019-12-22 04:11:13 +01:00
|
|
|
}
|
|
|
|
|
2019-01-27 17:37:44 +01:00
|
|
|
class Avatar extends StatelessWidget {
|
|
|
|
final String url;
|
2019-02-03 08:50:17 +01:00
|
|
|
final double size;
|
2019-12-27 08:06:45 +01:00
|
|
|
final String linkUrl;
|
2019-12-30 14:25:02 +01:00
|
|
|
final BorderRadius borderRadius;
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2019-12-27 08:06:45 +01:00
|
|
|
Avatar({
|
2019-10-02 09:23:33 +02:00
|
|
|
@required this.url,
|
2019-12-27 08:06:45 +01:00
|
|
|
this.size = AvatarSize.medium,
|
|
|
|
this.linkUrl,
|
2019-12-30 14:25:02 +01:00
|
|
|
this.borderRadius,
|
2019-12-27 08:06:45 +01:00
|
|
|
});
|
2019-12-22 04:11:13 +01:00
|
|
|
|
2019-01-27 17:37:44 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-01-12 14:39:03 +01:00
|
|
|
final widget = ClipRRect(
|
|
|
|
borderRadius: borderRadius ?? BorderRadius.circular(size / 2),
|
|
|
|
child: FadeInImage.assetNetwork(
|
|
|
|
placeholder: 'images/avatar.png',
|
|
|
|
image: url ?? 'images/avatar.png',
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
fadeInDuration: Duration(milliseconds: 200),
|
|
|
|
fadeOutDuration: Duration(milliseconds: 100),
|
2019-01-27 17:37:44 +01:00
|
|
|
),
|
2020-01-12 14:39:03 +01:00
|
|
|
);
|
|
|
|
if (linkUrl == null) return widget;
|
2020-01-13 14:07:28 +01:00
|
|
|
return Link(
|
2020-01-12 14:39:03 +01:00
|
|
|
child: widget,
|
2019-11-02 14:44:26 +01:00
|
|
|
onTap: () {
|
2020-01-12 14:39:03 +01:00
|
|
|
Provider.of<ThemeModel>(context).push(context, linkUrl);
|
2019-11-02 14:44:26 +01:00
|
|
|
},
|
2019-01-27 17:37:44 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-12-27 08:06:45 +01:00
|
|
|
|
|
|
|
class GithubAvatar extends StatelessWidget {
|
|
|
|
final String url;
|
|
|
|
final double size;
|
|
|
|
final String login;
|
|
|
|
|
|
|
|
GithubAvatar({
|
|
|
|
@required this.url,
|
|
|
|
this.size = AvatarSize.medium,
|
|
|
|
this.login,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Avatar(url: url, size: size, linkUrl: '/$login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GitlabAvatar extends StatelessWidget {
|
|
|
|
final String url;
|
|
|
|
final double size;
|
2019-12-30 13:55:37 +01:00
|
|
|
final int id;
|
2019-12-27 08:06:45 +01:00
|
|
|
|
|
|
|
GitlabAvatar({
|
|
|
|
@required this.url,
|
2019-12-30 14:25:02 +01:00
|
|
|
@required this.id,
|
2019-12-27 08:06:45 +01:00
|
|
|
this.size = AvatarSize.medium,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-12-30 14:25:02 +01:00
|
|
|
return Avatar(
|
|
|
|
url: url,
|
|
|
|
size: size,
|
|
|
|
linkUrl: '/user/$id',
|
|
|
|
);
|
2019-12-27 08:06:45 +01:00
|
|
|
}
|
|
|
|
}
|