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-23 12:28:33 +02:00
|
|
|
import 'package:git_touch/screens/repository.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 'link.dart';
|
|
|
|
|
2019-09-21 19:23:38 +02:00
|
|
|
const repoChunk = '''
|
|
|
|
owner {
|
|
|
|
login
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
name
|
|
|
|
description
|
|
|
|
isPrivate
|
|
|
|
isFork
|
|
|
|
stargazers {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
forks {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
primaryLanguage {
|
|
|
|
color
|
|
|
|
name
|
|
|
|
}
|
|
|
|
''';
|
|
|
|
|
2019-09-23 12:28:33 +02:00
|
|
|
class RepositoryItem 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-23 12:28:33 +02:00
|
|
|
RepositoryItem(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),
|
2019-09-13 17:34:19 +02:00
|
|
|
Text(numberFormat.format(payload['stargazers']['totalCount'])),
|
2019-09-09 16:50:22 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(Octicons.repo_forked,
|
|
|
|
size: 14, color: PrimerColors.gray600),
|
2019-09-13 17:34:19 +02:00
|
|
|
Text(numberFormat.format(payload['forks']['totalCount'])),
|
2019-09-09 16:50:22 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-26 20:04:27 +02:00
|
|
|
Widget _buildTopics() {
|
|
|
|
// TODO: link
|
|
|
|
return Wrap(
|
|
|
|
spacing: 4,
|
|
|
|
runSpacing: 4,
|
|
|
|
children: (payload['repositoryTopics']['nodes'] as List).map((node) {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: PrimerColors.blue000,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(4)),
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
node['topic']['name'],
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
color: PrimerColors.blue500,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-03 16:10:10 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-10-02 08:58:11 +02:00
|
|
|
// TODO: text style
|
|
|
|
return Link(
|
|
|
|
screenBuilder: inRepoScreen
|
|
|
|
? null
|
|
|
|
: (_) => RepositoryScreen(payload['owner']['login'], payload['name']),
|
|
|
|
child: Container(
|
2019-10-02 10:09:54 +02:00
|
|
|
padding: CommonStyle.padding,
|
2019-10-02 08:58:11 +02:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2019-10-02 09:23:33 +02:00
|
|
|
Avatar.small(
|
|
|
|
url: payload['owner']['avatarUrl'],
|
|
|
|
login: payload['owner']['login'],
|
|
|
|
),
|
2019-10-02 08:58:11 +02:00
|
|
|
SizedBox(width: 8),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: join(SizedBox(height: 8), <Widget>[
|
|
|
|
Row(
|
2019-10-02 09:55:25 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2019-10-02 08:58:11 +02:00
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
payload['owner']['login'] + ' / ',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: inRepoScreen ? 18 : 16,
|
|
|
|
color: PrimerColors.blue500,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
2019-09-09 16:50:22 +02:00
|
|
|
),
|
2019-10-02 08:58:11 +02:00
|
|
|
Text(
|
|
|
|
payload['name'],
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: inRepoScreen ? 18 : 16,
|
|
|
|
color: PrimerColors.blue500,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
),
|
2019-10-02 09:55:25 +02:00
|
|
|
Expanded(child: Container()),
|
|
|
|
Icon(_buildIconData(),
|
|
|
|
size: 18, color: PrimerColors.gray600),
|
2019-10-02 08:58:11 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
if (payload['description'] != null &&
|
|
|
|
(payload['description'] as String).isNotEmpty)
|
2019-09-09 16:50:22 +02:00
|
|
|
Text(
|
2019-10-02 08:58:11 +02:00
|
|
|
payload['description'],
|
2019-09-09 16:50:22 +02:00
|
|
|
style: TextStyle(
|
2019-10-02 08:58:11 +02:00
|
|
|
color: PrimerColors.gray700,
|
|
|
|
fontSize: inRepoScreen ? 15 : 14),
|
2019-09-09 16:50:22 +02:00
|
|
|
),
|
2019-10-02 08:58:11 +02:00
|
|
|
if (inRepoScreen) _buildTopics() else _buildStatus(),
|
|
|
|
]),
|
|
|
|
),
|
2019-02-04 11:32:39 +01:00
|
|
|
),
|
2019-10-02 08:58:11 +02:00
|
|
|
],
|
|
|
|
),
|
2019-02-03 16:10:10 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|