1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-16 18:28:51 +01:00

fix: table view style

This commit is contained in:
Rongjian Zhang 2019-09-15 15:08:09 +08:00
parent cce67cccda
commit 9bc5c2b96a
6 changed files with 136 additions and 122 deletions

View File

@ -85,26 +85,28 @@ class ObjectScreen extends StatelessWidget {
Widget _buildTree(payload) {
var entries = payload['entries'] as List;
return TableView(
hasIcon: true,
items: entries.map((item) {
return TableViewItem(
leftWidget: _buildIcon(item),
text: Text(item['name']),
screenBuilder: (_) {
if (item['type'] == 'commit') return null;
// TODO: All image types
var ext = path.extension(item['name']);
if (ext.isNotEmpty) ext = ext.substring(1);
if (['png', 'jpg', 'jpeg', 'gif', 'webp'].contains(ext)) {
return ImageView(NetworkImage('$rawUrl/' + item['name']));
}
return ObjectScreen(
name: name,
owner: owner,
branch: branch,
paths: [...paths, item['name']],
type: item['type'],
);
});
leftWidget: _buildIcon(item),
text: Text(item['name']),
screenBuilder: (_) {
if (item['type'] == 'commit') return null;
// TODO: All image types
var ext = path.extension(item['name']);
if (ext.isNotEmpty) ext = ext.substring(1);
if (['png', 'jpg', 'jpeg', 'gif', 'webp'].contains(ext)) {
return ImageView(NetworkImage('$rawUrl/' + item['name']));
}
return ObjectScreen(
name: name,
owner: owner,
branch: branch,
paths: [...paths, item['name']],
type: item['type'],
);
},
);
}),
);
}

View File

@ -225,53 +225,59 @@ class RepoScreen extends StatelessWidget {
),
),
),
TableView(items: [
TableViewItem(
leftIconData: Octicons.code,
text: Text('Code'),
rightWidget:
Text(filesize(payload['languages']['totalSize'] as int)),
screenBuilder: (_) => ObjectScreen(
owner: owner,
name: name,
branch: payload['defaultBranchRef']['name'], // FIXME: null
TableView(
hasIcon: true,
items: [
TableViewItem(
leftIconData: Octicons.code,
text: Text('Code'),
rightWidget:
Text(filesize(payload['languages']['totalSize'] as int)),
screenBuilder: (_) => ObjectScreen(
owner: owner,
name: name,
branch: payload['defaultBranchRef']['name'], // FIXME: null
),
),
),
TableViewItem(
leftIconData: Octicons.issue_opened,
text: Text('Issues'),
rightWidget:
Text(numberFormat.format(payload['issues']['totalCount'])),
screenBuilder: (_) => IssuesScreen(owner: owner, name: name),
),
TableViewItem(
leftIconData: Octicons.git_pull_request,
text: Text('Pull requests'),
rightWidget: Text(
numberFormat.format(payload['pullRequests']['totalCount'])),
screenBuilder: (_) =>
IssuesScreen(owner: owner, name: name, isPullRequest: true),
),
]),
TableViewItem(
leftIconData: Octicons.issue_opened,
text: Text('Issues'),
rightWidget: Text(
numberFormat.format(payload['issues']['totalCount'])),
screenBuilder: (_) => IssuesScreen(owner: owner, name: name),
),
TableViewItem(
leftIconData: Octicons.git_pull_request,
text: Text('Pull requests'),
rightWidget: Text(numberFormat
.format(payload['pullRequests']['totalCount'])),
screenBuilder: (_) => IssuesScreen(
owner: owner, name: name, isPullRequest: true),
),
],
),
borderView1,
TableView(items: [
TableViewItem(
leftIconData: Octicons.history,
text: Text('Commits'),
rightWidget: Text(numberFormat.format(
payload['defaultBranchRef']['target']['history']
['totalCount'])),
screenBuilder: (_) => CommitsScreen(owner, name),
),
TableViewItem(
leftIconData: Octicons.law,
text: Text('License'),
rightWidget: Text(payload['licenseInfo'] == null
? 'Unknown'
: (payload['licenseInfo']['spdxId'] ??
payload['licenseInfo']['name'])),
),
]),
TableView(
hasIcon: true,
items: [
TableViewItem(
leftIconData: Octicons.history,
text: Text('Commits'),
rightWidget: Text(numberFormat.format(
payload['defaultBranchRef']['target']['history']
['totalCount'])),
screenBuilder: (_) => CommitsScreen(owner, name),
),
TableViewItem(
leftIconData: Octicons.law,
text: Text('License'),
rightWidget: Text(payload['licenseInfo'] == null
? 'Unknown'
: (payload['licenseInfo']['spdxId'] ??
payload['licenseInfo']['name'])),
),
],
),
borderView1,
if (payload['object'] != null)
Container(

View File

@ -14,10 +14,7 @@ import '../screens/login.dart';
class SettingsScreen extends StatelessWidget {
Widget _buildRightWidget(bool checked) {
if (!checked) return null;
return Row(children: [
Icon(Octicons.check, color: CupertinoColors.activeBlue, size: 24),
SizedBox(width: 12)
]);
return Icon(Octicons.check, color: CupertinoColors.activeBlue, size: 24);
}
@override
@ -32,7 +29,6 @@ class SettingsScreen extends StatelessWidget {
borderView1,
TableView(headerText: 'ACCOUNTS', items: [
TableViewItem(
leftIconData: Icons.account_circle,
text: Text('Switch to another account'),
screenBuilder: (_) => LoginScreen(),
),
@ -40,7 +36,6 @@ class SettingsScreen extends StatelessWidget {
borderView1,
TableView(headerText: 'THEME', items: [
TableViewItem(
leftIconData: MaterialCommunityIcons.material_design,
text: Text('Material'),
rightWidget:
_buildRightWidget(themeProvider.theme == ThemeMap.material),
@ -52,7 +47,6 @@ class SettingsScreen extends StatelessWidget {
hideRightChevron: true,
),
TableViewItem(
leftIconData: MaterialCommunityIcons.apple,
text: Text('Cupertino'),
rightWidget: _buildRightWidget(
themeProvider.theme == ThemeMap.cupertino),
@ -67,12 +61,10 @@ class SettingsScreen extends StatelessWidget {
borderView1,
TableView(headerText: 'ABOUT', items: [
TableViewItem(
leftIconData: Octicons.code,
text: Text('Source code'),
text: Text('Source Code'),
screenBuilder: (_) => RepoScreen('pd4d10', 'git-touch'),
),
TableViewItem(
leftIconData: Octicons.law,
text: Text('License'),
rightWidget: Text('MIT'),
screenBuilder: (_) => ObjectScreen(
@ -84,8 +76,7 @@ class SettingsScreen extends StatelessWidget {
),
),
TableViewItem(
leftIconData: Icons.star,
text: Text('Rate this App'),
text: Text('Rate This App'),
onTap: () {
LaunchReview.launch(
androidAppId: 'io.github.pd4d10.gittouch',

View File

@ -233,43 +233,46 @@ class UserScreen extends StatelessWidget {
borderView1,
_buildContributions(contributions),
borderView1,
TableView(items: [
if (isNotNullOrEmpty(payload['company']))
TableViewItem(
leftIconData: Octicons.organization,
text: Text(payload['company']),
),
if (isNotNullOrEmpty(payload['location']))
TableViewItem(
leftIconData: Octicons.location,
text: Text(payload['location']),
onTap: () {
launch('https://www.google.com/maps/place/' +
(payload['location'] as String)
.replaceAll(RegExp(r'\s+'), ''));
},
),
if (isNotNullOrEmpty(payload['email']))
TableViewItem(
leftIconData: Octicons.mail,
text: Text(payload['email']),
onTap: () {
launch('mailto:' + payload['email']);
},
),
if (isNotNullOrEmpty(payload['websiteUrl']))
TableViewItem(
leftIconData: Octicons.link,
text: Text(payload['websiteUrl']),
onTap: () {
var url = payload['websiteUrl'] as String;
if (!url.startsWith('http')) {
url = 'http://$url';
}
launch(url);
},
),
]),
TableView(
hasIcon: true,
items: [
if (isNotNullOrEmpty(payload['company']))
TableViewItem(
leftIconData: Octicons.organization,
text: Text(payload['company']),
),
if (isNotNullOrEmpty(payload['location']))
TableViewItem(
leftIconData: Octicons.location,
text: Text(payload['location']),
onTap: () {
launch('https://www.google.com/maps/place/' +
(payload['location'] as String)
.replaceAll(RegExp(r'\s+'), ''));
},
),
if (isNotNullOrEmpty(payload['email']))
TableViewItem(
leftIconData: Octicons.mail,
text: Text(payload['email']),
onTap: () {
launch('mailto:' + payload['email']);
},
),
if (isNotNullOrEmpty(payload['websiteUrl']))
TableViewItem(
leftIconData: Octicons.link,
text: Text(payload['websiteUrl']),
onTap: () {
var url = payload['websiteUrl'] as String;
if (!url.startsWith('http')) {
url = 'http://$url';
}
launch(url);
},
),
],
),
..._buildRepos(payload),
],
);

View File

@ -155,7 +155,13 @@ class BorderView extends StatelessWidget {
Widget build(BuildContext context) {
return Row(
children: <Widget>[
SizedBox(width: leftPadding),
SizedBox(
width: leftPadding,
height: 1,
child: DecoratedBox(
decoration: BoxDecoration(color: PrimerColors.white),
),
),
Expanded(
child: SizedBox(
height: height,

View File

@ -27,18 +27,23 @@ class TableViewItem {
class TableView extends StatelessWidget {
final String headerText;
final Iterable<TableViewItem> items;
final bool hasIcon;
TableView({this.headerText, @required this.items});
double get _leftPadding => hasIcon ? 44 : 12;
TableView({this.headerText, @required this.items, this.hasIcon = false});
Widget _buildItem(TableViewItem item) {
if (item == null) return null;
var leftWidget = item.leftWidget ??
Icon(
item.leftIconData,
color: PrimerColors.blue500,
size: 18,
);
var leftWidget = item.leftWidget;
if (leftWidget == null && hasIcon) {
leftWidget = Icon(
item.leftIconData,
color: PrimerColors.blue500,
size: 18,
);
}
// Container(
// width: 24,
// height: 24,
@ -55,7 +60,7 @@ class TableView extends StatelessWidget {
color: PrimerColors.white,
child: Row(
children: [
SizedBox(width: 44, child: leftWidget),
SizedBox(width: _leftPadding, child: leftWidget),
Expanded(child: item.text),
if (item.rightWidget != null) ...[
DefaultTextStyle(
@ -101,7 +106,8 @@ class TableView extends StatelessWidget {
),
),
borderView,
...join(BorderView(leftPadding: 44), items.map(_buildItem).toList()),
...join(BorderView(leftPadding: _leftPadding),
items.map(_buildItem).toList()),
borderView,
],
);