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

138 lines
4.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2019-02-04 14:38:29 +01:00
import 'package:flutter/cupertino.dart';
2019-09-08 15:20:12 +02:00
import 'package:git_touch/widgets/avatar.dart';
2019-08-31 16:17:35 +02:00
import 'package:primer/primer.dart';
import '../utils/utils.dart';
import '../screens/repo.dart';
import 'link.dart';
class RepoItem extends StatelessWidget {
2019-03-02 11:17:46 +01:00
final Map<String, dynamic> payload;
2019-09-09 16:50:22 +02:00
final bool inRepoScreen;
2019-09-09 16:50:22 +02:00
RepoItem(this.payload, {this.inRepoScreen = false});
2019-02-04 11:32:39 +01:00
IconData _buildIconData() {
2019-03-02 11:17:46 +01:00
if (payload['isPrivate']) {
2019-02-04 11:32:39 +01:00
return Octicons.lock;
}
2019-03-02 11:17:46 +01:00
if (payload['isFork']) {
2019-02-04 11:32:39 +01:00
return Octicons.repo_forked;
}
return Octicons.repo;
}
2019-09-09 16:50:22 +02:00
Widget _buildStatus() {
return DefaultTextStyle(
style: TextStyle(
color: PrimerColors.gray800,
fontSize: 13,
fontWeight: FontWeight.w500,
),
child: Row(
children: <Widget>[
Expanded(
child: Row(children: <Widget>[
Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: convertColor(payload['primaryLanguage'] == null
? null
: payload['primaryLanguage']['color']),
shape: BoxShape.circle,
),
),
SizedBox(width: 4),
Text(payload['primaryLanguage'] == null
? 'Unknown'
: payload['primaryLanguage']['name']),
]),
),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(Octicons.star, size: 14, color: PrimerColors.gray600),
Text(payload['stargazers']['totalCount'].toString()),
],
),
),
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(Octicons.repo_forked,
size: 14, color: PrimerColors.gray600),
Text(payload['forks']['totalCount'].toString())
],
),
),
],
),
);
}
@override
Widget build(BuildContext context) {
var widget = Padding(
padding: EdgeInsets.all(10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
2019-09-08 15:20:12 +02:00
Avatar(url: payload['owner']['avatarUrl'], size: 12),
SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2019-09-08 15:20:12 +02:00
children: join(SizedBox(height: 8), <Widget>[
2019-09-09 16:50:22 +02:00
Row(
children: <Widget>[
Text(
payload['owner']['login'] + ' / ',
style: TextStyle(
fontSize: 16,
color: PrimerColors.blue500,
fontWeight: FontWeight.w500,
),
),
Text(
payload['name'],
2019-09-09 16:50:22 +02:00
style: TextStyle(
fontSize: 16,
color: PrimerColors.blue500,
fontWeight: FontWeight.w600,
),
),
],
2019-08-31 16:17:35 +02:00
),
2019-09-08 15:20:12 +02:00
payload['description'] == null ||
(payload['description'] as String).isEmpty
? null
: Text(
payload['description'],
style: TextStyle(
2019-09-09 16:50:22 +02:00
color: PrimerColors.gray700, fontSize: 14),
2019-09-08 15:20:12 +02:00
),
2019-09-09 16:50:22 +02:00
...(inRepoScreen ? [] : [_buildStatus()])
2019-09-08 15:20:12 +02:00
]),
2019-02-04 11:32:39 +01:00
),
),
2019-09-08 15:20:12 +02:00
Icon(_buildIconData(), size: 18, color: PrimerColors.gray600),
],
),
);
2019-09-09 16:50:22 +02:00
if (inRepoScreen) {
2019-09-11 13:45:34 +02:00
return widget;
} else {
// TODO: text style
return Link(
screenBuilder: (_) =>
RepoScreen(payload['owner']['login'], payload['name']),
child: widget,
);
}
}
}