git-touch-android-ios-app/lib/widgets/avatar.dart

85 lines
1.9 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2019-11-02 14:44:26 +01:00
import 'package:git_touch/models/theme.dart';
import 'package:provider/provider.dart';
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;
}
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-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
@override
Widget build(BuildContext context) {
2019-11-02 14:44:26 +01:00
return GestureDetector(
child: ClipRRect(
2019-12-30 14:25:02 +01:00
borderRadius: borderRadius ?? BorderRadius.circular(4),
2019-11-02 14:44:26 +01:00
child: FadeInImage.assetNetwork(
2019-12-22 04:05:55 +01:00
placeholder: 'images/avatar.png',
image: url ?? 'images/avatar.png',
2019-11-02 14:44:26 +01:00
width: size,
height: size,
fadeInDuration: Duration(milliseconds: 200),
fadeOutDuration: Duration(milliseconds: 100),
),
),
2019-11-02 14:44:26 +01:00
onTap: () {
2019-12-27 08:06:45 +01:00
if (linkUrl != null)
Provider.of<ThemeModel>(context).push(context, linkUrl);
2019-11-02 14:44:26 +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',
borderRadius: BorderRadius.circular(size / 2),
);
2019-12-27 08:06:45 +01:00
}
}