git-touch-android-ios-app/lib/widgets/repo_item.dart

159 lines
4.3 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';
2019-09-21 19:23:38 +02:00
const repoChunk = '''
owner {
login
avatarUrl
}
name
description
isPrivate
isFork
stargazers {
totalCount
}
forks {
totalCount
}
primaryLanguage {
color
name
}
''';
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(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),
Text(numberFormat.format(payload['forks']['totalCount'])),
2019-09-09 16:50:22 +02:00
],
),
),
],
),
);
}
@override
Widget build(BuildContext context) {
2019-09-14 20:05:34 +02:00
var widget = Container(
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(
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(
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-12 10:30:35 +02:00
if (!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,
);
}
}
}