2019-02-03 16:10:10 +01:00
|
|
|
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';
|
2019-02-03 16:10:10 +01:00
|
|
|
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-02-03 16:10:10 +01:00
|
|
|
|
2019-09-09 16:50:22 +02:00
|
|
|
RepoItem(this.payload, {this.inRepoScreen = false});
|
2019-02-03 16:10:10 +01:00
|
|
|
|
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())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-03 16:10:10 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-03-10 10:24:03 +01:00
|
|
|
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),
|
2019-03-10 10:24:03 +01:00
|
|
|
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(
|
2019-03-10 10:24:03 +01:00
|
|
|
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-03-10 10:24:03 +01:00
|
|
|
),
|
2019-09-08 15:20:12 +02:00
|
|
|
Icon(_buildIconData(), size: 18, color: PrimerColors.gray600),
|
2019-03-10 10:24:03 +01:00
|
|
|
],
|
2019-02-03 16:10:10 +01:00
|
|
|
),
|
|
|
|
);
|
2019-03-10 10:24:03 +01:00
|
|
|
|
2019-09-09 16:50:22 +02:00
|
|
|
if (inRepoScreen) {
|
2019-09-11 13:45:34 +02:00
|
|
|
return widget;
|
|
|
|
} else {
|
2019-03-10 10:24:03 +01:00
|
|
|
// TODO: text style
|
|
|
|
return Link(
|
|
|
|
screenBuilder: (_) =>
|
|
|
|
RepoScreen(payload['owner']['login'], payload['name']),
|
|
|
|
child: widget,
|
|
|
|
);
|
|
|
|
}
|
2019-02-03 16:10:10 +01:00
|
|
|
}
|
|
|
|
}
|