1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-18 19:22:54 +01:00
git-touch-android-ios-app/lib/widgets/avatar.dart
2019-10-02 15:23:33 +08:00

57 lines
1.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import '../screens/user.dart';
import 'link.dart';
class Avatar extends StatelessWidget {
final String url;
final String login;
final double size;
Avatar({
@required this.url,
this.login,
@required this.size,
});
Avatar.extraSmall({
@required this.url,
this.login,
}) : size = 16;
Avatar.small({
@required this.url,
this.login,
}) : size = 24;
Avatar.medium({
@required this.url,
this.login,
}) : size = 36;
Avatar.large({
@required this.url,
this.login,
}) : size = 48;
@override
Widget build(BuildContext context) {
var avatar = ClipRRect(
borderRadius: BorderRadius.circular(4),
child: FadeInImage.assetNetwork(
placeholder: 'images/octoface.png',
image: url,
width: size,
height: size,
fadeInDuration: Duration(milliseconds: 200),
fadeOutDuration: Duration(milliseconds: 100),
),
);
if (login == null) {
return avatar;
} else {
return Link(
screenBuilder: (_) => UserScreen(login),
child: avatar,
);
}
}
}