1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 10:48:50 +01:00

fix: use readme api

This commit is contained in:
Rongjian Zhang 2019-09-23 19:45:47 +08:00
parent 88509f9872
commit b07b25fca0

View File

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:filesize/filesize.dart'; import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -102,11 +104,6 @@ class RepositoryScreen extends StatelessWidget {
name name
} }
} }
object(expression: "$_branchName:README.md") {
... on Blob {
text
}
}
licenseInfo { licenseInfo {
name name
spdxId spdxId
@ -118,11 +115,25 @@ class RepositoryScreen extends StatelessWidget {
return data['repository']; return data['repository'];
} }
Future<String> fetchReadme(BuildContext context) async {
var data = await Provider.of<SettingsModel>(context)
.getWithCredentials('/repos/$owner/$name/readme');
if (data['content'] == null) {
return null;
}
var bits = base64.decode((data['content'] as String).replaceAll('\n', ''));
var str = utf8.decode(bits);
return str;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RefreshScaffold( return RefreshScaffold(
title: AppBarTitle('Repository'), title: AppBarTitle('Repository'),
trailingBuilder: (payload) { trailingBuilder: (data) {
var payload = data[0];
return ActionButton(title: 'Repository Actions', actions: [ return ActionButton(title: 'Repository Actions', actions: [
MyAction( MyAction(
text: '@$owner', text: '@$owner',
@ -170,8 +181,14 @@ class RepositoryScreen extends StatelessWidget {
), ),
]); ]);
}, },
onRefresh: () => queryRepo(context), onRefresh: () => Future.wait([
bodyBuilder: (payload) { queryRepo(context),
fetchReadme(context),
]),
bodyBuilder: (data) {
var payload = data[0];
var readme = data[1] as String;
final langWidth = MediaQuery.of(context).size.width - final langWidth = MediaQuery.of(context).size.width -
_languageBarPadding * 2 - _languageBarPadding * 2 -
(payload['languages']['edges'] as List).length + (payload['languages']['edges'] as List).length +
@ -312,10 +329,10 @@ class RepositoryScreen extends StatelessWidget {
], ],
), ),
borderView1, borderView1,
if (payload['object'] != null) if (readme != null)
Container( Container(
padding: EdgeInsets.all(16), padding: EdgeInsets.all(16),
child: MarkdownView(payload['object']['text']), child: MarkdownView(readme),
), ),
], ],
); );