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-09-14 20:05:34 +02:00
|
|
|
var widget = Container(
|
2019-03-10 10:24:03 +01:00
|
|
|
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(
|
2019-09-13 09:55:58 +02:00
|
|
|
fontSize: inRepoScreen ? 18 : 16,
|
2019-09-09 16:50:22 +02:00
|
|
|
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(
|
2019-09-13 09:55:58 +02:00
|
|
|
fontSize: inRepoScreen ? 18 : 16,
|
2019-09-09 16:50:22 +02:00
|
|
|
color: PrimerColors.blue500,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2019-08-31 16:17:35 +02:00
|
|
|
),
|
2019-09-14 11:19:33 +02:00
|
|
|
if (payload['description'] != null &&
|
|
|
|
(payload['description'] as String).isNotEmpty)
|
|
|
|
Text(
|
|
|
|
payload['description'],
|
|
|
|
style: TextStyle(
|
|
|
|
color: PrimerColors.gray700,
|
|
|
|
fontSize: inRepoScreen ? 15 : 14),
|
|
|
|
),
|
2019-09-26 20:04:27 +02:00
|
|
|
if (inRepoScreen) _buildTopics() else _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: (_) =>
|
2019-09-23 12:28:33 +02:00
|
|
|
RepositoryScreen(payload['owner']['login'], payload['name']),
|
2019-03-10 10:24:03 +01:00
|
|
|
child: widget,
|
|
|
|
);
|
|
|
|
}
|
2019-02-03 16:10:10 +01:00
|
|
|
}
|
|
|
|
}
|