1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-20 20:13:55 +01:00
git-touch-android-ios-app/lib/widgets/repo_item.dart
2019-08-31 22:18:15 +08:00

98 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:primer/primer.dart';
import '../utils/utils.dart';
import '../screens/repo.dart';
import 'link.dart';
class RepoItem extends StatelessWidget {
final Map<String, dynamic> payload;
final bool showOwner;
final bool isLink;
RepoItem(this.payload, {this.showOwner = true, this.isLink = true});
IconData _buildIconData() {
if (payload['isPrivate']) {
return Octicons.lock;
}
if (payload['isFork']) {
return Octicons.repo_forked;
}
return Octicons.repo;
}
@override
Widget build(BuildContext context) {
var widget = Padding(
padding: EdgeInsets.all(10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
(showOwner ? (payload['owner']['login'] + '/') : '') +
payload['name'],
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 16),
),
SizedBox(height: 6),
Text(
payload['description'] ?? 'No description provided yet',
style: TextStyle(color: PrimerColors.gray600, fontSize: 14),
),
SizedBox(height: 6),
DefaultTextStyle(
style: TextStyle(color: PrimerColors.gray600, fontSize: 13),
child: Row(
children: <Widget>[
Icon(Octicons.star,
size: 14, color: PrimerColors.gray600),
Text(payload['stargazers']['totalCount'].toString()),
SizedBox(width: 16),
Icon(Octicons.repo_forked,
size: 14, color: PrimerColors.gray600),
Text(payload['forks']['totalCount'].toString()),
SizedBox(width: 16),
payload['primaryLanguage'] == null
? Container()
: Row(children: <Widget>[
Container(
width: 10,
height: 10,
decoration: new BoxDecoration(
color: convertColor(
payload['primaryLanguage']['color']),
shape: BoxShape.circle,
),
),
Padding(padding: EdgeInsets.only(left: 4)),
Text(payload['primaryLanguage']['name']),
]),
],
),
)
],
),
),
Padding(padding: EdgeInsets.only(left: 4)),
Icon(_buildIconData(), size: 20, color: Colors.black54),
],
),
);
if (isLink) {
// TODO: text style
return Link(
screenBuilder: (_) =>
RepoScreen(payload['owner']['login'], payload['name']),
child: widget,
);
} else {
return widget;
}
}
}